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

Script does not have logic to re-map a network drive when a UNC path is changed #49

Open lms93 opened 1 year ago

lms93 commented 1 year ago

How do I ensure that the script can handle updates to UNC paths? Would I need to look at removing and disconnecting existing drives if the script needs to be rerun? Thank you

lms93 commented 1 year ago

@nicolonsky Any ideas mate?

lms93 commented 1 year ago

Hey @nicolonsky
Your help would be appreciated mate, surely there would be many others with this issue? Cheers

Aas42 commented 11 months ago

Also have questions regarding this, did you figure something out?

stephannn commented 3 months ago

Shouldn't line: if ($null -ne $exists -and $($exists.Path -eq $drive.Path -and $exists.DriveLetter -eq $drive.DriveLetter )) { do the trick?

ThomSerree commented 4 weeks ago

The line:

Get-PSDrive | Where-Object { $_.DisplayRoot -eq $drive.Path -or $_.Name -eq $drive.DriveLetter } | Remove-PSDrive -EA SilentlyContinue

should remove inconsistent drive mappings when the script is updated. However Remove-PSDrive does not remove the mapping fully and you cannot add another mapping on the same drive letter in the same script.

I did a quick fix in my code by commenting out that line and adding a good old net use command.

$netUseDrive = $drive.DriveLetter + ":"             
Write-Output "Deleting drive with with command: net use $netUseDrive /delete /y"
net use $netUseDrive /delete /y