Need to remap network drives to DFS
We are moving over to DFS namespace and I need to create a script that will remap our users that have network drives to DFS. Has anyone created a script for that?
All Replies
- Hi,
If you want to use a WSH script, check out the WshNetwork object's EnumNetworkDrives method. Using this method, you can detect what drives are mapped, and to where. You can then use the RemoveNetworkDrive method to remove the old drive mapping and the MapNetworkDrive method to map the drive to the new location.
Bill Where in this script would I apply the "RemoveNetworkDrive"? I am not an expert in VB. Any help would be appreciated?
- Hi,
Do you have any experience in writing VBScript scripts? If not, then I recommend you get a good book and/or some training.
Bill Here's what I have so far..
If StrComp("x:", \\servername\) = 0 Then'remove the existing share
objNetwork.RemoveNetworkDrive "x:", True, True
objNetwork.RemoveNetworkDrive "m:", True, True
'give operation a moment to finish
wscript.sleep 200
end if'remap the drive to the new server
objNetwork.MapNetworkDrive "x:", \\company\dfsroot
objNetwork.MapNetworkDrive "m:", \\company\dfsroot
It still does not map to the DFS. Any suggestions on what the script? Any help would be appreciated. Thanks- Hi,
Here's the rough approach I would use:
Dim WshNetwork, Drives, N, Drive, UNCPath Set WshNetwork = CreateObject("WScript.Network") Set Drives = WshNetwork.EnumNetworkDrives For N = 0 To Drives.Count - 1 Step 2 Drive = Drives.Item(N) UNCPath = Drives.Item(N + 1) Select Case Drive Case "X:" If LCase(UNCPath) = "\\server\share1" Then WshNetwork.RemoveNetworkDrive "X:", True, True WshNetwork.MapNetworkDrive "X:", "\\dfsroot\path 1" End If Case "Y:" If LCase(UNCPath) = "\\server\share2" Then WshNetwork.RemoveNetworkDrive "Y:", True, True WshNetwork.MapNetworkDrive "Y:", "\\dfsroot\path 2" End If End Select Next
HTH,
Bill Thanks I'll try from here. I'll follow up with if successful or not.
- The x: file ran flawlessly. The y: is a user's folder redirect, in other words the user has a username folder(on the file server) that is redirected to their desktop. Any suggestions.
- Are you talking about folder redirection from a GPO?
Bill Correct?
- Correct!
- Then isn't the fix to correct the setting(s) in the GPO?
Bill - The redirect folder is correct in our GPO. I've applied this script to a GPO and have it pointing to my test OU. I get the same results.
- Hi, please post the GPO settings you are using, and the code that is not working. If you get an error message, please post the exact error message (including line number).
Bill

