Solved

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

Posted on 2011-09-12
9
537 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:exNavyNuke
  • 4
  • 4
9 Comments
 
LVL 7

Expert Comment

by:Jacobfw
ID: 36526867
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
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36526881
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

0
 

Author Comment

by:exNavyNuke
ID: 36526909
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.
0
 

Author Comment

by:exNavyNuke
ID: 36533192
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36533533
OK, it may need a bit of a wait.

Change this bit:
			objNetwork.RemoveNetworkDrive strDriveLetter
			objNetwork.MapNetworkDrive strDriveLetter, strNewPath

Open in new window


to this:
			objNetwork.RemoveNetworkDrive strDriveLetter
			WScript.Sleep 3000
			objNetwork.MapNetworkDrive strDriveLetter, strNewPath

Open in new window


to wait three seconds after disconnecting the drive.

Regards,

Rob.
0
 

Author Comment

by:exNavyNuke
ID: 36533588
Will try this at work again tomorrow.  Thanks for sticking with me.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36533600
Sure, no worries.
0
 

Author Closing Comment

by:exNavyNuke
ID: 36577195
Adding the additional 3 seconds seemed to have solved the problem.  Thanks!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36577486
Great! Thanks for the grade.

Rob.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now