Windows Server 2003 Terminal server easiest way to view all mapped drives for all users and the drive status

Solution 1:

Tentative answer - iterate through the users under HKEY_USERS and extract the contents of the Network key. That won't tell you for all users logged in, that will tell you for all users that ever logged in. If you need it fancier, you could parse usernames from the output of qwinsta, correlate that to the SIDs under HKEY_USERS, and then pull only their Network keys.

I'm sure it would be easiest to do in PowerShell (which might have more built-in methods to do this anyway), but since you're on Win2k3, I'm not going to assume that's installed.

Edit- ok, now with that explanation of the problem, why don't you add a line to the start of your TS login scripts to do a net use * /delete ? Then map everything after that. If anyone needs a mapped drive, add that into their login scripts.

Solution 2:

The following wmic commandline will return all mapped drives not in Connected state.

wmic /node:"ServerName" netuse where connectionstate!="Connected" get localname, name, username

The following will return all mapped drives regardless of the connection state:

wmic /node:"Sedlmeyer-PC" netuse get localname, name, username

You can also remove the "get localname, name, username" and replace with list to get full details. If you run the command local to the server you can leave off the /node.

You also add a /format option to change how the info is output. For instance /format:csv will generate it in csv format, /format:htable will output it as a HTML table, and /format:xml as XML. If you add /output:"filename" as the first argument it will save the output to the specified file. If you use /output:clipboard it will place th eoutput in the clipboard.

More info on wmic can be found here.

Solution 3:

Add something like the following to your logon script

echo %date%,%time%,%computername%,%username% >> \\fileserver\hiddenshare$\drives.csv
net use >> \\fileserver\hiddenshare$\drives.csv

Make sure to give all your users write access to the share, then let it populate.

After a day or two you'll have a great CSV file you can load up in Excel, sort on User, and flip around the data however works best for you.