Ldap – How to query members of an Exchange distribution group using LDAP filter syntax

active-directoryldapquery

I'm trying to use a couple of Exchange distribution lists for access to an application (the list, due to the culture at this particular enterprise, is kept more up to date with people moving in and out than many of the security groups).

The problem here is that I can't seem to construct a filter that will retrieve list members.

Example, say the distribution list exists at

CN=\#Accounting Users,OU=DistributionLists,OU=Groups,DC=enterprise,DC=com

..one would expect to be able to retrieve its user account members with the filter syntax:

(&
  (objectCategory=Person)
  (sAMAccountName=*)
  (memberOf=CN=\#Accounting Users,OU=DistributionLists,OU=Groups,DC=enterprise,DC=com)
)

This filter as written returns an error, indicating that my "memberOf" syntax is invalid. I think it's choking on the backslash before the hash sign, even though it's explicitly shown to be there in the distinguishedName field of the group.

If I remove the backslash, the search completes, but returns nothing.

The members of the list have the usual memberOf attributes on their account objects.

What am I doing wrong here, and how do I make the search work?

Best Answer

Try this one:

(&
  (objectCategory=Person)
  (sAMAccountName=*)
  (memberOf=CN=\5C\5C#Accounting Users,OU=DistributionLists,OU=Groups,DC=enterprise,DC=com)
)

I built it with the help of Adaxes and it works on my side.