?
Solved

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

Posted on 2011-09-12
9
Medium Priority
?
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

765 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