Search code examples
active-directoryldapldap-query

Cannot get list of groups users in AD - memberOf function not working


This query works fine:

(&(objectCategory=user)(objectClass=user)(memberOf=*) )

but any ever, with selection of group - with no result

(&(objectCategory=user)(objectClass=user)(memberOf=myGroup) )

(&(objectCategory=user)(objectClass=user)(memberOf=CN=myGroup) )

(&(objectCategory=user)(objectClass=user)(memberOf:1.2.840.113556.1.4.1941:=CN=myGroup) )

Solution

  • It's because memberof attribute stores dn values, so you have to provide a dn in the filter.

    And by dn I mean a full dn all the way to the root of the ldap directory tree.

    If your group : CN=myGroup is in the branch ou=groups and the baseDn of your directory is dc=local,dc=com, you have to specify a filter like :

    memberof=CN=myGroup,ou=groups,dc=local,dc=com