MCPJoe
asked on
script to change existing drive mappings to point to new servername
Can anyone help me with this? I'm trying to find a way to script the modification of existing Windows 2000/XP drive mappings through vbscript. I am migrating file servers and want to find a way to simply email a script to my users that will change their existing drive mappings to point to the new file server. I know there must be a way to do this. Any help is appreciated.
Basically, want to change existing drive mapping (\\servera\sharename) to a new server name with the same sharename (\\serverb\sharename).
Thanks
Basically, want to change existing drive mapping (\\servera\sharename) to a new server name with the same sharename (\\serverb\sharename).
Thanks
ASKER
My users will likely have at least two drive mappings with various drive letters, (drive letters won't be the same from PC to PC). Is there an easy way to check for a drive mapping, then change the servername path if it matches the old server name? Then map the drive with the new servername and make it persistent?
Thanks
Thanks
Something like this?
Dim WshNetwork,drv,DriveList,x
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set DriveList = WshNetwork.EnumNetworkDriv es
For x = 1 to DriveList.Count Step 2
if Lcase(DriveList.Item(x)) = Lcase("\\servera\share") Then
drv = DriveList.Item(x -1)
WshNetwork.RemoveNetworkDr ive drv, true, true
WshNetwork.MapNetworkDrive drv, "\\serverb\sharename"
end if
Next
Set WshNetwork = Nothing
Dim WshNetwork,drv,DriveList,x
Set WshNetwork = WScript.CreateObject("WScr
Set DriveList = WshNetwork.EnumNetworkDriv
For x = 1 to DriveList.Count Step 2
if Lcase(DriveList.Item(x)) = Lcase("\\servera\share") Then
drv = DriveList.Item(x -1)
WshNetwork.RemoveNetworkDr
WshNetwork.MapNetworkDrive
end if
Next
Set WshNetwork = Nothing
ASKER
So that will search through the existing drive mappings, check if a particular server is used, then delete the drive mappins and re-create them with the new servername?
Thanks
Thanks
Actually that is checking for the full share name. I think you want something like this:
Dim WshNetwork,drv,DriveList,x ,NewShare
Set WshNetwork = WScript.CreateObject("WScr ipt.Networ k")
Set DriveList = WshNetwork.EnumNetworkDriv es
For x = 1 to DriveList.Count Step 2
if Instr(Lcase(DriveList.Item (x)),Lcase ("\\server a\")) > 0 Then
NewShare = Replace(DriveList.Item(x), "\\servera \","\\serv erb\")
drv = DriveList.Item(x -1)
WshNetwork.RemoveNetworkDr ive drv, true, true
WshNetwork.MapNetworkDrive drv, NewShare
end if
Next
Set WshNetwork = Nothing
Dim WshNetwork,drv,DriveList,x
Set WshNetwork = WScript.CreateObject("WScr
Set DriveList = WshNetwork.EnumNetworkDriv
For x = 1 to DriveList.Count Step 2
if Instr(Lcase(DriveList.Item
NewShare = Replace(DriveList.Item(x),
drv = DriveList.Item(x -1)
WshNetwork.RemoveNetworkDr
WshNetwork.MapNetworkDrive
end if
Next
Set WshNetwork = Nothing
ASKER
Ok, I'll give that a shot. Will that map the drive as persistent?
ooops,forgot that. Change this line:
WshNetwork.MapNetworkDrive drv, NewShare
To:
WshNetwork.MapNetworkDrive drv, NewShare , True
WshNetwork.MapNetworkDrive
To:
WshNetwork.MapNetworkDrive
ASKER
When I run your script, I get
Line 10
Char 9
Error: the network name cannot be found
code: 80070043
Source: WSHNetwork.MapNetworkDrive
How can I fix that?
Thanks
Joe
Line 10
Char 9
Error: the network name cannot be found
code: 80070043
Source: WSHNetwork.MapNetworkDrive
How can I fix that?
Thanks
Joe
That means the script found a share on the old server that does not exist on the new server.
ASKER
Oh ok. Sorry, my mistake. Thanks again!!!! It worked then, I was wondering why it was doing one drive, but not the other. I appreciate the help!!!
thanks
Joe
thanks
Joe
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thats ok, I want this to be transparent, because end users may be running this script. Thanks for your help!!! It works!!!
Dim WshNetwork,fso
Set WshNetwork = WScript.CreateObject("WScr
Set fso = CreateObject("Scripting.Fi
if fso.DriveExists("S") Then
WshNetwork.RemoveNetworkDr
end if
WshNetwork.MapNetworkDrive
Set fso = Nothing
Set WshNetwork = Nothing