Link to home
Start Free TrialLog in
Avatar of exNavyNuke
exNavyNukeFlag for United States of America

asked on

vbs to remap drives to new server with same named shares as old server

I'm migrating to a new file server that will have all of the same share names as the old file server.  The difference will be the new server name.  I need a script that functions similar to the Microsoft 'Hey Scripting guy article' at http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/28/how-can-i-find-all-the-drives-mapped-to-a-share-and-remap-them.aspx except as is mentioned at the end of the article I need the script to remap all the mapped drives on the client to the new server name.  The script will be run on each client at my facility after the switch to the new server.
Avatar of Jacobfw
Jacobfw
Flag of Canada image

We use Kixtart for this type of logon scripting excercise.

http://www.kixtart.org/

there are several internet examples, but if you need an example, I can supply one should you wish to use kixtart.

Jacob
Avatar of RobSampson
Hi, this should work.

Regards,

Rob.
On Error Resume Next

strOldServer = "server1"
strNewServer = "server2"

Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objNetwork.EnumNetworkDrives
For i = 0 to colDrives.Count-1 Step 2
	strThisServer = Left(Mid(colDrives.Item(i + 1), 3), InStr(Mid(colDrives.Item(i + 1), 3), "\") - 1)
	If LCase(strThisServer) = LCase(strOldServer) Then
		strDriveLetter = colDrives.Item(i)
		strNewPath = "\\" & strNewServer & "\" & Mid(colDrives.Item(i + 1), Len("\\" & strOldServer & "\") + 1)
		If objFSO.FolderExists(strNewPath) = True Then
			objNetwork.RemoveNetworkDrive strDriveLetter
			objNetwork.MapNetworkDrive strDriveLetter, strNewPath
		End If
	End If
Next

Open in new window

Avatar of exNavyNuke

ASKER

Thanks Jacobfw.  I'm a little bit familiar with Kixstart.  Our corporate network team uses it for login scripts. But I need this to be a VB script that I can run on individual PCs. I don't have access to run login scripts.

Rob - I will try this at work tomorrow.  I hope it's exactly what I need.
I tried the script on some test shares between two servers at work and something isn't working right.  The code seems perfect and I can step through it and see what it does or what it's trying to do.  But for some reason it unmaps (or disconnects) the drive letters but they don't map to the new server.

The objNetwork.MapNetworkDrive strDriveLetter, strNewPath line seems to be correct and yet I just end up with drive letters to the old server that show as disconnected in windows explorer (actually I use Directory Opus at work and the drive letters show up as disconnected).

I'm going to setup a totally separate test environment with a couple of servers and see what happens with those.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Will try this at work again tomorrow.  Thanks for sticking with me.
Sure, no worries.
Adding the additional 3 seconds seemed to have solved the problem.  Thanks!
Great! Thanks for the grade.

Rob.