Hi, all. I'm new to vbscript and need some assistance, please. I found the script below and tweaked it a little to work in our environment. We're migrating file servers to a new server with a different name, so we have to change any static drive mappings from the old server name to the new.
Below works as it should, but I need it to ignore the H: drive. I still want to change any other drive letters, just don't want to touch the H: drive because it'll remove it, remap it to point to the new server name as a 'persistent' drive instead of non-persistent. I guess making sure the script maps the drive the same way (non-persistent or persistent) would work, too, but just ignoring H: might be easier, no?
Anyway, any help would be greatly appreciated!
Thanks in advance
strOldServer = "\\oldserver_name\"
strNewServer = "\\newserver_name\"
Set objNetwork = CreateObject("WScript.Network")
Set objDrives = objNetwork.EnumNetworkDrives
For i = 0 To objDrives.Count - 1 Step 2
strDrive = objDrives(i)
strPath = objDrives(i + 1)
If Left(LCase(strPath), Len(strOldServer)) = strOldServer Then
strNewPath = Replace(strPath, strOldServer, strNewServer, vbTextCompare)
'WScript.Echo "Disconnecting " & strDrive & " from " & strPath & " and mapping it to " & strNewPath
On Error Resume Next
objNetwork.RemoveNetworkDrive strDrive, True, True
WScript.Sleep 3000
Err.Clear
On Error GoTo 0
objNetwork.MapNetworkDrive strDrive, strNewPath, True
End If
Next
Below works as it should, but I need it to ignore the H: drive. I still want to change any other drive letters, just don't want to touch the H: drive because it'll remove it, remap it to point to the new server name as a 'persistent' drive instead of non-persistent. I guess making sure the script maps the drive the same way (non-persistent or persistent) would work, too, but just ignoring H: might be easier, no?
Anyway, any help would be greatly appreciated!
Thanks in advance
strOldServer = "\\oldserver_name\"
strNewServer = "\\newserver_name\"
Set objNetwork = CreateObject("WScript.Network")
Set objDrives = objNetwork.EnumNetworkDrives
For i = 0 To objDrives.Count - 1 Step 2
strDrive = objDrives(i)
strPath = objDrives(i + 1)
If Left(LCase(strPath), Len(strOldServer)) = strOldServer Then
strNewPath = Replace(strPath, strOldServer, strNewServer, vbTextCompare)
'WScript.Echo "Disconnecting " & strDrive & " from " & strPath & " and mapping it to " & strNewPath
On Error Resume Next
objNetwork.RemoveNetworkDrive strDrive, True, True
WScript.Sleep 3000
Err.Clear
On Error GoTo 0
objNetwork.MapNetworkDrive strDrive, strNewPath, True
End If
Next