Q:

Batch To Find All Drive Letters Of Specific Path Mapping

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.

A:

net use will 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 /f loop to check the path, and if it matches delete the drive letter in the 2nd part
for /f "tokens=2,3" %%a in ('net use') do if .%%b==.\\Server\DriveCaseSensitive net use %%a /Delete

This means that it will also detect and remove mappings if the drive has been mapped multiple times

