0

I'm in the process of moving file servers. Once completed, I will have to change the UNC path that the mapped drive letters used network wide to point to the new machine. I want to handle the change through a VBS logon script that I'll attach to OUs to map different drives.

The goal for the script is to first grab the UNC path for the F: (or whatever drive); if it equals "\old_server\files" then disconnect it and then reconnect it as "\new_server\files". Otherwise, do nothing. There's 5 paths/drives total that this will need to happen for.

I tried using Computer Performance's Already Connected Script but couldn't get it to work. It didn't disconnect the old drive when testing it out on multiple machines.

Any help is appreciated.

3 Answers3

3

If you have a domain, then I'd look at doing a Group Policy Preference for the drive mapping. You should be able to have it map a given UNC to a given drive, and automatically replace any old mappings that exist.

Mike Renfro
  • 1,301
2

Since you're really only testing for the existence of the old mapping and deleting that in order to make the new mapping, why not just use a Net X: /delete for the drive letters that you typically have mapped and then proceed with your Net Use X: statements. It won't do any harm to delete and remap a connection if it already exists for the new server.

joeqwerty
  • 111,849
0

Bit late but is this want you want? this would have to be run locally on each pc - e.g in a login script like you say

Set objShell = CreateObject("Wscript.Shell")

Set objNet = WScript.CreateObject("Wscript.Network") 

Set objExec = objShell.Exec("net use ") 
strMaps = LCase(objExec.StdOut.ReadAll)
MapArray=split(strMaps,CHR(10))

for x=1 to ubound(mapArray) 

    if instr(mapArray(x),"i:") AND instr(mapArray(x),"\oldserver1\sharex$") then 
        objNet.RemoveNetworkDrive "i:",true,true
        objNet.MapNetworkDrive "I:" , "\newserver1\shareX" 
    end if

    if instr(mapArray(x),"j:") AND instr(mapArray(x),"\\oldserver2\shareY$") then
            objNet.RemoveNetworkDrive "J:"
            objNet.MapNetworkDrive "J:" , "\\newserver2\shareX$"  
    end if  

next
user9517
  • 117,122
Mark
  • 1