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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Active Directory Groups a User Belongs To

Status
Not open for further replies.

bob000

Programmer
Aug 23, 2001
20
US
Microsoft provides this script at:
-------------------------
On Error Resume Next
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D

Set objUser = GetObject _
("LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,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=NA,dc=fabrikam,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

objConnection.Close
---------------
Can someone explain this line and where each parameter comes from in an Active Directory. My script errors on this line that I have changed for my environment.

Set objUser = GetObject _
(&quot;LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com&quot;)
 
What is the error?

Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
The error I am getting is:
There is no such object on the server, Thx.
 
Have you set up this line

(&quot;LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com&quot;)

To point to your own user, OU and domain?

[auto] MCSE NT4/W2K
 
Ok in this line:
(&quot;LDAP://cn=MyerKen,ou=Management,dc=NA,dc=fabrikam,dc=com&quot;)
cn=MyerKen !this is the user
ou=Management !I changed this to &quot;Users&quot; were our users, are in Active Directory, correct?
dc=NA !what it this?
dc=fabrikam !domain
dc=com !domain name extension
 
I think &quot;Users&quot; is &quot;seen&quot; as a container and not a OU in AD.

Try (&quot;LDAP://cn=lastname firstname,cn=users,dc=...)

hope this helps!
 
Code:
>dc=NA           !what it this?
>dc=fabrikam     !domain
>dc=com          !domain name extension
Domain is : NA.fabrikam.com (I guess ...)

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top