Search code examples
active-directoryldapldap-query

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.


Solution

  • 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.