LDAP query not working but I don't know why

  • Thread starter Thread starter dln
  • Start date Start date
D

dln

Hello all. I'm trying to find the right group to post this to and since
it's a coding question (of sorts), hopefully this is the right place. I'm
attempting to run an LDAP query to return the Recipient Update Policies on
an Exchange server using the DirectorySearcher class, but it's not returning
any results. The following is a snippet of code outlining what I'm trying
to do:

DirectorySearcher searcher = new DirectorySearcher();
searcher.SearchRoot.Path = "LDAP://cn=Recipient
Policies,cn=<org>,cn=Microsoft
Exchange,cn=Services,cn=Configuration,dc=<domain>";
searcher.Filter = "(&(objectClass=msExchRecipientPolicy))";
SearchResultCollection matched = searcher.FindAll(); // nothing is
returned

If I use a utility like "ADSI Edit", I can look at the AD Configuration
naming context and then view the Recipient Update Policies for the
organization, so I know that they do exist. Additionally, if I change my
filter to something like "(&(objectClass=*))", I get a bunch of results but
none of them are for the Recipient Update Policies. Does anybody have an
idea of what I'm doing wrong or if there is a better, more appropriate way
to retrieve the Recipient Update Policies from AD.

Thanks.
 
Figured it out - I should be setting the "searcher.SearchRoot" property to a
DirectoryEntry object instead of modifying "searcher.SearchRoot.Path".

dln.
 
Back
Top