Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving the AD Groups a user belongs to

Status
Not open for further replies.

Alekctx

Technical User
Nov 25, 2002
2
FR
Hi
I guess I am to tired
Could someone tell me why does this script not work?

Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D

Set objUser = GetObject _
("LDAP://cn=TOTO,ou=rx250,dc=test,dc=X34-001,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 = _
&quot;<LDAP://dc=test,dc=X34-001,dc=com>;(objectCategory=Group);&quot; & _
&quot;distinguishedName,primaryGroupToken;subtree&quot;
Set objRecordSet = objCommand.Execute

While Not objRecordset.EOF
If objRecordset.Fields(&quot;primaryGroupToken&quot;) = intPrimaryGroupID Then
WScript.Echo &quot;Primary group:&quot;
WScript.Echo objRecordset.Fields(&quot;distinguishedName&quot;) & _
&quot; (primaryGroupID: &quot; & intPrimaryGroupID & &quot;)&quot;
End If
objRecordset.MoveNext
Wend
 
On a quick look I would guess you are missing the .Name object syntax:
Code:
    For each Group in arrMemberOf
        WScript.Echo Group
.Name
Code:
    Next

Another syntax (not LDAP) but the same idea:

Code:
      Set DomainObj = GetObject(&quot;WinNT://DomainName&quot;)
      DomainObj.Filter = Array(&quot;Group&quot;)
      For Each Group in DomainObj
        Response.Write(Group
.Name
Code:
)
        Response.Write(Group
.Description
Code:
)
      Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top