Solved

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

Posted on 2011-09-12
9
562 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
Technology Partners: 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!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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