We had a script push out to map a new drive, but net use R: /Delete was not used so the drive is still there and there are incorrect mappings to the next available letter for hundreds of users. I need to delete all incorrect mappings and was hoping there was a batch script that would scan for a specific mapping and then pipe the drive letter.
Set Path = \\Drive\Folder
Set DriveLetter = ?Scan all mapped drives for %Path%?
Net Use %DriveLetter% /Delete
Looking to fill in the blanks here.
net usewill show drive mappings (connected or not)example output:
New connections will be remembered. Status Local Remote Network ------------------------------------------------------------------------------- Disconnected Q: \\Server1\Drive Microsoft Windows Network OK S: \\Server2\Drive2 Microsoft Windows Network The command completed successfully.looking at this output, the 2nd column, gives us the drive letter, and the 3rd gives us the path. putting this into a
for /floop to check the path, and if it matches delete the drive letter in the 2nd partThis means that it will also detect and remove mappings if the drive has been mapped multiple times