Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to list all users of a certain group

How can I use a a search filter to display users of a specific group?

I've tried the following:

(&     (objectCategory=user)     (memberOf=MyCustomGroup) ) 

and this:

(&     (objectCategory=user)     (memberOf=cn=SingleSignOn,ou=Groups,dc=tis,dc=eg,dc=ddd,D‌​C=com) )    

but neither display users of a specific group.

like image 576
Madam Zu Zu Avatar asked Mar 27 '12 13:03

Madam Zu Zu


People also ask

How do I list all users in ad group?

Use Get-ADGroupMember cmdlet to List Members of an Active Directory Group. The PowerShell Get-ADGroupMember cmdlet is used to list the members of an Active Directory group. You can just type the cmdlet in a PowerShell window and you'll be prompted to enter the name of the group you want to use.

How do I list users in LDAP?

On the navigation tree, select Device User > LDAP Users from the navigation tree. The list displays all LDAP users and includes the following columns: Account Name—Account name of the LDAP user. Device User Group—Device user group to which the LDAP user belongs.

What is MemberOf in LDAP?

MemberOf is an LDAP AttributeType where the value is the DN of an LDAP Entry is the Group that the current LDAP Entry is a member in a Group and is referred to as a Forward Reference. ( or Virtual Attribute)


2 Answers

memberOf (in AD) is stored as a list of distinguishedNames. Your filter needs to be something like:

(&(objectCategory=user)(memberOf=cn=MyCustomGroup,ou=ouOfGroup,dc=subdomain,dc=domain,dc=com)) 

If you don't yet have the distinguished name, you can search for it with:

(&(objectCategory=group)(cn=myCustomGroup)) 

and return the attribute distinguishedName. Case may matter.

like image 143
Kodra Avatar answered Oct 06 '22 06:10

Kodra


For Active Directory users, an alternative way to do this would be -- assuming all your groups are stored in OU=Groups,DC=CorpDir,DC=QA,DC=CorpName -- to use the query (&(objectCategory=group)(CN=GroupCN)). This will work well for all groups with less than 1500 members. If you want to list all members of a large AD group, the same query will work, but you'll have to use ranged retrieval to fetch all the members, 1500 records at a time.

The key to performing ranged retrievals is to specify the range in the attributes using this syntax: attribute;range=low-high. So to fetch all members of an AD Group with 3000 members, first run the above query asking for the member;range=0-1499 attribute to be returned, then for the member;range=1500-2999 attribute.

like image 23
sigint Avatar answered Oct 06 '22 08:10

sigint