Set objUser = Nothing
Set objAD = Nothing
Set objGroups = Nothing
Function getUserGroups(objUser)
Set retDict = CreateObject("Scripting.Dictionary")
'Get memberof memberships
If Not IsEmpty(objUser.memberof) Then
For Each memberOfDN In objUser.GetEx("memberof")
retDict.Add memberOfDN, memberOfDN
Next
End If
'Query AD for all group objects (used to locate primary group)
Set objConn = CreateObject("ADODB.Connection")
Set objComm = CreateObject("ADODB.Command")
objConn.Provider = "ADsDSOObject"
objConn.Open "Active Directory Provider"
Set objComm.ActiveConnection = objConn
objComm.Properties("Page Size") = 1000
objComm.CommandText = "<LDAP://" & objRootDSE.get("defaultNamingContext") & ">;(objectclass=group);distinguishedName,primaryGroupToken;subtree"
Set objRS = objComm.Execute
objRS.MoveFirst
Do
If objRS.Fields("primaryGroupToken").Value = objUser.Get("primaryGroupID") Then retDict.Add objRS.Fields(0).Value, objRS.Fields(0).Value
objRS.MoveNext
Loop Until objRS.EOF
Set getUserGroups = retDict
Set retDict = Nothing
Set objRootDSE = Nothing
Set objConn = Nothing
Set objComm = Nothing
Set objRS = Nothing
End Function
Set objAD = CreateObject("ADSystemInfo")
Set objuser = GetObject("LDAP://" & objAD.UserName)
Set objRootDSE = GetObject("LDAP://RootDSE")
Set objNet = CreateObject("Wscript.Network")
Set objGroups = getUserGroups(objUser)
For Each key In objGroups.Keys
'WScript.Echo objGroups.Item(key)
Next
'This is where you test on group membership:
If objGroups.Exists("CN=TEST1,OU=TEST2,OU=TEST3,DC=domain,DC=local") Then
objNet.MapNetworkDrive "X:", "\\host\shared"
End If
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE