Very useful on File Servers migrations, this script was created and used on login script of 1000+ users after migration from Novell file server to a new Windows file server. The script reduces the calls on service desk after migration, reading what mapped drivers each user has and creating a new mapped driver.
Basically, you need specify share names that you wanna modify and put this script to run on login script. After a file server migration, users run login script and remap automatically network drivers.
On Error Resume Next
Const iDebug = 1 ‘If different of 0, writes a log file
Const iNumPaths = 4 ‘Number of Paths to be modifiedDim name
Dim old_path(4), new_path(4), Path_name(4)
Dim Letter_Name(25,2)
Dim Letter_Remaps, iCount
Dim objPing, strUserName‘====
‘Define Paths
‘====old_path(1)=”\\NWFSrc15\Vol1\users”
new_path(1)=”%USER%”
Path_name(1) = “Wsrcspfs03″old_path(2)=”\\NWFSrc15\Vol1″
new_path(2)=”\\172.20.200.30\vol1″
Path_name(2) = “Wsrcspfs05″old_path(3)=”\\NWFSrc10\Vol1\users”
new_path(3)=”%USER%”
Path_name(3) = “Wsrcspfs03″old_path(4)=”\\NWFSrc10\Vol1″
new_path(4)=”\\172.20.200.29\vol2″
Path_name(4) = “Wsrcspfs04″‘====
‘Objects
‘====Set objWMIService=GetObject(”winmgmts:\\.\root\cimv2″)
Set WshNetwork = WScript.CreateObject(”WScript.Network”)
Set WshShell = createobject(”WScript.Shell”)
Set objShell = CreateObject(”Shell.Application”)
Set colDisks = objWMIService.ExecQuery(”Select * from Win32_NetworkConnection”)
Set oFileSys=CreateObject(”Scripting.FileSystemObject”)
if iDebug then
Set oFile=oFileSys.CreateTextFile(”C:\map_log.txt”)
end ifif iDebug then
oFile.writeline “Process started on: ” & Now()
oFile.writeline “# Drives befor process: ” & colDisks.count
end if‘====
‘Execute Ping to force Name Resolution
‘====Set objPing = GetObject(”winmgmts:{impersonationLevel=impersonate}”)._
ExecQuery(”select * from Win32_PingStatus where address = ’servername’”)For iPath = 1 to iNumPaths
For Each objDisk In colDisks
strMapeamento = objDisk.RemoteName
If instr(ucase(strMapeamento),ucase(old_path(iPath))) then
Letra = objDisk.LocalName‘=== If new_path = “%USER%”, script will map user home directory
if new_path(iPath)=”%USER%” then
strUserName = WshNetwork.UserName
path = “\\wsrcspfs03\Users1\” & strUserName
if iDebug then oFile.writeline ” %USER% = ” & path & ” >> ” & oFileSys.FolderExists(path)
if not oFileSys.FolderExists(path) Then
path = “\\wsrcspfs03\Users2\” & strUserName
End If
Else‘=== Else will map the new_path variable
path = Replace(ucase(strMapeamento),ucase(old_path(iPath)),ucase(new_path(iPath)))
End If‘=== Remove map
if iDebug then oFile.writeline “Drive: ” & Letra & ” >> Old Map: ” & strMapeamento & ” >> New Map: ” & path
WshShell.Run “NET USE ” & Letra & ” /DELETE”,0,True‘=== Map!
WShNetwork.MapNetworkDrive Letra, path, True
If Err.Number <> 0 Then
if iDebug then ofile.wscript “An error occurred on create a mapped drive for: ” & path
Err.Clear
WshShell.Run “NET USE ” & Letra & ” ” & chr(34) & path & chr(34) & ” /PERSISTENT:YES”,0,True
End If‘=== Store in an array names for letters
Letter_Remaps = Letter_Remaps + 1
Letter_Name(Letter_Remaps,1) = trim(Letra) & “\”
Letter_Name(Letter_Remaps,2) = mid(path,instrrev(path,”\”) + 1,len(path)) & ” on ” & path_name(iPath)
End if
Next
Set colDisks = objWMIService.ExecQuery(”Select * from Win32_NetworkConnection”)Next
For iCount = 1 to Letter_Remaps
objShell.NameSpace(Letter_Name(iCount,1)).Self.Name = Lcase(Letter_Name(iCount,2))
Nextif iDebug then
oFile.writeline “# Drives after process: ” & colDisks.count
oFile.writeline “Process finished on: ” & Now()
oFile.Close
end if
2 Responses
Suryanto
January 4th, 2009 at 12:39 pm
1I am doing a file server migration from serverA to serverB.
Some of the network drives mapping for our users are from our Windows login script,
however majority of the users do their own network drive mapping.
Will your script work to re-map user’s network drive mapping from serverA to serverB?
e.g. if they have R: drive mapped to \\serverA\Dept\Finance, can your script re-map it to
\\serverB\Dept\Finance ?
Dept is our shared name.
Thank you in advance.
Roberto
January 4th, 2009 at 12:41 pm
2Yes, that script will re-map network drive mappings from serverA to serverB of each user runnig the script.
Let’s say that a user has these maps:
h: \\serverXX\comercial\test
o: \\siteh\technical
r: \\serverA\dept\Finance
u: \\serverA\sales
If you put in the script to change just from \\serverA to \\serverB, the user above will have the letters r: remapped to \\serverB\dept\Finance and u: to \\serverB\sales.
If you put in the script to change from \\serverA\dept to \\serverB\dept, the user above will have only the letter r: remapped to \\serverB\dept\Finance.
Basically the script will search for drives that contains the text of the variable old_path, if some driver is founded, the script will delete that driver and recreate the same driver using replacing the text of old_path variable by the text of new_path variable, keeping the remaning path of the driver.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Articles
Pages
Subscribe by RSS or Email
Recent Articles
Links