I seem to be having problems. I want to pull a list of groups that a particular user has listed and then map drives to that user according to group membership. I want to write one script for my whole company. This script will base it's search on the login name. Well when i do an ldap search on login name it says no such object exists. Yet when i hard code the Full name it works see example below. I would really appreciate some help. Thanks in advance. I have to hard code John Doe but i would rather use login name of the client pc.
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Set objUser = GetObject _
("LDAP://cn=John Doe,ou=MIS,dc=xyz,dc=wxyz,dc=com"
intPrimaryGroupID = objUser.Get("primaryGroupID"
arrMemberOf = objUser.GetEx("memberOf"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "The memberOf attribute is not set."
Else
WScript.Echo "Member of: "
For each Group in arrMemberOf
WScript.Echo Group
Next
End If
Set objConnection = CreateObject("ADODB.Connection"
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=xyz,dc=wxyz,dc=com>;(objectCategory=Group);" & _
"distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute
While Not objRecordset.EOF
If objRecordset.Fields("primaryGroupToken"
= intPrimaryGroupID Then
WScript.Echo "Primary group:"
WScript.Echo objRecordset.Fields("distinguishedName"
& _
" (primaryGroupID: " & intPrimaryGroupID & "
"
End If
objRecordset.MoveNext
Wend
objConnection.Close
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Set objUser = GetObject _
("LDAP://cn=John Doe,ou=MIS,dc=xyz,dc=wxyz,dc=com"
intPrimaryGroupID = objUser.Get("primaryGroupID"
arrMemberOf = objUser.GetEx("memberOf"
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo "The memberOf attribute is not set."
Else
WScript.Echo "Member of: "
For each Group in arrMemberOf
WScript.Echo Group
Next
End If
Set objConnection = CreateObject("ADODB.Connection"
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command"
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=xyz,dc=wxyz,dc=com>;(objectCategory=Group);" & _
"distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute
While Not objRecordset.EOF
If objRecordset.Fields("primaryGroupToken"
WScript.Echo "Primary group:"
WScript.Echo objRecordset.Fields("distinguishedName"
" (primaryGroupID: " & intPrimaryGroupID & "
End If
objRecordset.MoveNext
Wend
objConnection.Close