I have been testing parts of our software lately (Alpha stuff that will be released in a few months). One problem I keep running into, is I collect up a large number of mapped drives that are unavailable:
This is because the machine is powered off, or is a virtual machine that I deleted.
I like to use the same set of drive letters for testing, since it makes it simpler, and I don’t have to keep changing paths. The problem is that once a drive becomes ‘unavailable’ you need to to explicitly disconnect each one by using the command:
net use /delete [drive]
I was getting tired of doing this all the time, so I built a script that will automatically clear out disconnected or unavailable drives.
Here is the script:
for /F "tokens=1-3" %%a in ('net use') do (
if /i %%a==Disconnected net use /delete %%b
if /i %%a==Unavailable net use /delete %%b
It loops through all the network connections, and looks for ‘Disconnected’ or ‘Unavailable’ and runs a ‘net use /delete [drive]’ against it.
I ran it once on my machine:
It cleared out all of those unavailable drives in a few seconds.
This can be helpful in your login scripts too – if the user has failed mappings from before, it can prevent your logon script from properly mapping to the correct server.
If you want to create a shortcut to it on your desktop, just create a new text file, name it “clear_drives.bat” and put the above script in.
Now if you want to clear out your unavailable drives you just need to double click on a shortcut, instead of wasting time in the command line.
One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools