nicolonsky / IntuneDriveMapping

Generate PowerShell scripts to map network drives on Intune managed Windows 10 devices
https://intunedrivemapping.azurewebsites.net/
MIT License
148 stars 17 forks source link

Update drive mapping issue #31

Open bjhitm opened 3 years ago

bjhitm commented 3 years ago

Hi great script and with the addition from intune.training is working very well for remote users still needing a vpn connection etc.

This has all deployed via Intune\endpoint manager like a dream. I've now changed a couple of UNC paths to use a DFS path. I can see the new DriveMapping.ps1 is deployed correctly but the drive mapping doesn't update. If I manually delete the drive mapping the next time the task runs it will create the mapping using the new correct path so it's just the deletion of the old one not working.

Looking at DriveMapping.log I do see an error but I can't figure out why it's not deleting and re-creating the drive mapping

Mapping network drive \xxxxx.local\xxxxxxData\Store PS>TerminatingError(New-PSDrive): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: The local device name is already in use" C:\ProgramData\intune-drive-mapping-generator\DriveMappping.ps1 : The local device name is already in use At line:1 char:3

Any thoughts?

Thanks Barry

DaBXRoMeO commented 2 years ago

I'm not sure if this will help, but I had a similar request where they wanted the path to self correct in the event that a user changed path. I added a block in the script after the comment line 117. It checks to see if the drive letter and path match. If not, it deletes the mapping and the rest of the script continues to create the intended letter\path. Just make sure to update the intended path(s) in the script below. I hope this helps.

if (-not (Test-RunningAsSystem)) {

$driveMappings = Get-WmiObject -Class Win32_mappedLogicalDisk | select name,providername
$Sdrive = "S:"
$Mdrive = "M:"

foreach ($driveMapping in $driveMappings){

    if ($driveMapping.name -match $Sdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use S: /delete
            }
    }
    if ($driveMapping.name -match $Mdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use M: /delete
            }
    }
}

Start-Sleep -Seconds 10

lms93 commented 1 year ago

I'm not sure if this will help, but I had a similar request where they wanted the path to self correct in the event that a user changed path. I added a block in the script after the comment line 117. It checks to see if the drive letter and path match. If not, it deletes the mapping and the rest of the script continues to create the intended letter\path. Just make sure to update the intended path(s) in the script below. I hope this helps.

if (-not (Test-RunningAsSystem)) {

$driveMappings = Get-WmiObject -Class Win32_mappedLogicalDisk | select name,providername
$Sdrive = "S:"
$Mdrive = "M:"

foreach ($driveMapping in $driveMappings){

    if ($driveMapping.name -match $Sdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use S: /delete
            }
    }
    if ($driveMapping.name -match $Mdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use M: /delete
            }
    }
}

Start-Sleep -Seconds 10

Hey @DaBXRoMeO Did you add this after commented section #Mapping network drives# ?

DaBXRoMeO commented 1 year ago

I'm not sure if this will help, but I had a similar request where they wanted the path to self correct in the event that a user changed path. I added a block in the script after the comment line 117. It checks to see if the drive letter and path match. If not, it deletes the mapping and the rest of the script continues to create the intended letter\path. Just make sure to update the intended path(s) in the script below. I hope this helps. if (-not (Test-RunningAsSystem)) {

$driveMappings = Get-WmiObject -Class Win32_mappedLogicalDisk | select name,providername
$Sdrive = "S:"
$Mdrive = "M:"

foreach ($driveMapping in $driveMappings){

    if ($driveMapping.name -match $Sdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use S: /delete
            }
    }
    if ($driveMapping.name -match $Mdrive){
        if ($driveMapping.ProviderName -ne '<intended path>') {
            net use M: /delete
            }
    }
}

Start-Sleep -Seconds 10

Hey @DaBXRoMeO Did you add this after commented section #Mapping network drives# ?

Correct, after the comment section that starts "#Mapping network drive#"

lms93 commented 1 year ago

Thanks @DaBXRoMeO I've found that with the added code of yours it still will continue to remove and replace the UNC path regardless of it being correct on the client end or not...