LDAP query to get members for all groups in a sub OU

groupsldap

I need to get all users that are members of a set of groups that are configured on a sub OU.

The DN for this sub OU is "OU=OU2,OU=1,DC=labo,DC=test".
The groups would be in "CN="",OU=OU2,OU=1,DC=labo,DC=test".

There is a way to execute a query that gets me all users members of these groups?

Best Answer

You should query for the virtual attributs representing users membership, it would a simple ldap search, something like:

 ldapsearch -h localhost --port 1389 -D "cn=Directory Manager" -w "password" -b "ou=people,o=group" -s sub "(ismemberof=CN=*,OU=OU2,OU=1,DC=labo,DC=test)" 

Note that some ldaps use memberof instead of ismemberof.