

SUBST with no parameters will display current SUBST drives You can use the underscore as a 1 character wild card in place of a slash since there currently isn’t a way to escape a backslash character.Substitute a drive letter for a network or local path. For now, you just edit the WMIC command to change the path to what you are looking for.
#Net use remove mapped drive update
One improvement could be to update the script to accept a parameter which would be the server path string you want to search for and you could enter this from the Group Policy logon scripts interface. REM loop through file of drive letters to removeįor /F %%A in (c:drivesbaddrives2.txt) do net use %%A /DELETE More c:drivesbaddrives.txt +1 > c:drivesbaddrives2.txt Wmic netuse where "RemotePath like '%%servername%%'" get localname > c:drivesbaddrives.txt REM '%%servername_sharename%%' would match \servernamesharename Use underscore in place of a slash for a 1 character wild card REM REM Script unmaps drives with a particular string in the path Part of that is knowing my environment, so this script is at work in my environment to clean up old drive off You use a WMIC command to filter your drive letters to those that match the UNC path you are interested in. There is certainly room for improvement or more gracefully handling errors but it fails through silently without getting hung up and completes successfully. Thanks but that’s not really a great solution…Īnywho, this is what I came up with. There were various responses asking endless questions or less helpful suggestions like use “net use * /delete and then map the drives you want with Group Policy Preferences”. Worst of all, there were plenty of threads on various sites asking to solve this exact problem but others did not understand it. The second reason this solution is rather satisfying that there was no clear, straight-forward solution online. Using something like WMIC netuse where “RemotePath like ‘\servername’ DELETE results in “ERROR: Description = Provider is not capable of the attempted operation.” Using WMI, you can implement some filtering logic with WHERE statements and LIKE comparison operators but WMIC does not have permission to modify or delete network connections for some reason. Net Use \servershare /delete but once it has been assigned a drive letter, you have to use that for the disconnect script. For example, you can disconnect a network share by the UNC path if it hasn’t been assigned a drive letter e.g. The first problem was that Microsoft’s built-in tools do not have a smart way of handling this problem. This solution was a little more satisfying than most because I did a lot of research online going down various paths. You would run into the same problem with using Group Policy Preferences to Delete a connection by drive letter. To utilize a script, it’s going to have to have some intelligence built into it to ensure you are disconnecting the correct drives. However, many organizations are in chaos with mapped drive letters and if you ran a script like that to delete all Z drives, you might disconnect some current, useful drives with clients that don’t know the path where it was mapped. Scripting the removal is also easy if you know the drive letter.

There are also command line options if you’re at the computer with the user logged in. You just right click on the drive and choose ‘Disconnect’. It’s a pretty simple process to disconnect a mapped drive when you are in front of the computer. Since they could be a confusing interface and disconnected drives might slow down the computer until they time out, it’s not a bad idea to clean up the old ones.
:max_bytes(150000):strip_icc()/net-use-help-windows-10-f078cd0562a04adb8e08203e0467ad20.png)
You can love ’em or hate ’em.Īfter changing file servers or retiring an old server, clients might have old mapped drives pointing to these servers.
