Solved

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

Posted on 2011-09-12
9
520 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

19 Experts available now in Live!

Get 1:1 Help Now