I am writing a login script which unmaps and remaps some drives.
The powershell calls a small batch file for the actual unmapping, as Powershell seems a bit flaky at reliably mapping the drives.
The code I am using is:
$arrDrives = "m:","n:","o:","p:","q:","r:","s:","u:","v:","x:","y:"
foreach ($drive in $arrDrives) {
if (test-path $drive) {
UpdateSubHeading ("Removing drive " + $drive)
c:\bin\removeDrive.bat $drive }
}
And the batch file it calls is just:
if exist %1 net use %1 /del
This all works fine, unless there is an open connection to the drive it is trying to unmap. If the user has a file open, then it hangs.
Is there a way I can check if there are any connections open to the mapped drive before I try and unmap it, and skip unmapping it if there are?
Thanks,
Ben
The script is probably waiting for permission to delete the connection
e.g.
You need to provide the permission on the command line
e.g
or in your case