Submitted By: Robert Joseph

Remaps user drive mappings from \\server\sharename to \\root\dfspath\sharename.

Visual Basic
On Error Resume Next 

Set WshNet = CreateObject("WScript.Network")

' Create a collection of mapped drives
Set WS_NetworkDrives = WshNet.EnumNetworkDrives

' Put you full qualified dfs path here without the last backslash
dfsPath = "\\root\dfspath"

' Loop through the collection
For i = 0 To WS_NetworkDrives.Count - 1 Step 2

' Since we don't want to unmap and remap everytime a user logs on we're going to check to see if they have an old mapping
' In this case we are migrating shares from 3 servers to dfs so replace server1, 2, etc with the name of the server, as
' far as I know you can append as many OR's to this as you like.  No backslashes are needed just the servername.
	If InStr(lcase(WS_NetworkDrives(i + 1)), "server1") Or InStr(lcase(WS_NetworkDrives(i + 1)), "server2") Or InStr(lcase(WS_NetworkDrives(i + 1)), "server3") Then
' 	We need to get the sharename the user has a mapping to so we cut it out using a parse function...
' 	Mad Props to Richard Mueller for showing me how to parse text
		shareName = Parse(lcase(WS_NetworkDrives(i + 1)))
' 		Disconnect the old drive mapping and update the users profile
' 		Use on error resume next in this script corrupted profiles can gererate an error here if you don't
		WshNet.RemoveNetworkDrive WS_NetworkDrives(i), True, True

' 		hang on a 1/4 sec
		WScript.Sleep 250
' 		Remap the drive and make it permanent
		WshNet.MapNetworkDrive WS_NetworkDrives(i), dfsPath & shareName, True
	End If

' Parse function cuts out \sharename from \\server\sharename
Function Parse(strDN)
	Parse = Mid(strDN, InStr(strDN, "\") + 2)
	Parse = Mid(Parse, InStr(Parse, "\"))
End Function