Skip to content

Instantly share code, notes, and snippets.

@jjeising
Created July 6, 2017 19:25
Show Gist options
  • Save jjeising/6213a3202a1ea794763431639c41188d to your computer and use it in GitHub Desktop.
Save jjeising/6213a3202a1ea794763431639c41188d to your computer and use it in GitHub Desktop.
Connect network drives based on old usernames (maybe on other file servers) and based on group membership
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
accountNameHistory = objUser.Get("accountNameHistory")
accountName = ""
If IsArray(accountNameHistory) Then
For Each line in accountNameHistory
accountName = line
Next
Else
accountName = accountNameHistory
End If
Set groups = CreateObject("Scripting.Dictionary")
For Each g in objUser.Groups
groups.Add g.CN, "-"
Next
Set WSHNetwork = CreateObject("WScript.Network")
WSHNetwork.MapNetworkDrive "G:", "[share]", False, accountName
' Error -2147024811 - Drive is already conncted
If ((Err.Number <> 0) And (Err.Number <> -2147024811)) Then
WScript.Echo "Failed to connect. Maybe the password is not the same?"
Else
If groups.Exists("group1")
WSHNetwork.MapNetworkDrive "H:", "[share2]", False, "[otherUser]", "[otherPassword]"
End If
If groups.Exists("group2")
WSHNetwork.MapNetworkDrive "I:", "[share3]", False, accountName
End If
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment