I'm trying to get a list of all my mapped drives for a system upgrade and would like to get this info via a batch file. How can I do this?
For Bonus points: How can I script the mapping of these drives on the new server?
I'm trying to get a list of all my mapped drives for a system upgrade and would like to get this info via a batch file. How can I do this?
For Bonus points: How can I script the mapping of these drives on the new server?
You can do this using vbscript
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive in colDrives
Wscript.Echo "Drive letter: " & objDrive.DriveLetter
Next
And you can map network drives with
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "G:", "\\Server\Path"
To list the mapped drives
Net Use
To map a new drive
Net Use G: \\Server\Path
The list of current mappings will be returned by
net use
The transfer would work like this (for the fun1 of it, lets do that in batch script instead of VBScript):
@echo off
setlocal EnableDelayedExpansion
set letter=.
set uncpath=.
set colon=.
for /f "delims=" %%l in ('net use') do @(
for /f "tokens=2" %%t in ("%%l") do @set letter=%%t
for /f "tokens=3" %%t in ("%%l") do @set uncpath=%%t
set colon=!letter:~1,1!
if "!colon!" EQU ":" (
echo if exist !letter! net use !letter! /delete
echo net use !letter! !uncpath! /persistent:yes
)
)
endlocal
output goes something like this:
if exist M: net use M: /delete
net use M: \\someserver\someshare /persistent:yes
if exist N: net use N: /delete
net use N: \\otherserver\othershare /persistent:yes
Just store that in a batch file and you are good to go.
1 Actually, "fun" is not the right word here. ;-)