How to include multiple OU from AD account in a single search using PrincipleSearcher in asp.net c#

2.8k Views Asked by At

Scenario: Active Directory username search should return results against a search item (i.e. Firstname or Surname). There are 6 countries that are setup as different organizational units for AD accounts. e.g. UK (OU= UK), France (OU = FR). Now user should be displayed with a username which may belong to either OU=UK or OU=FR.

I am using PrincipalSearcher from System.DirectoryServices.AccountManagement library

 PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "myDomain",
                                                    "OU=UK,dc=comp,dc=com");

Problem: The above allows to return usernames which only belongs to OU=UK.

Question: How can I add multiple Organizational Units in PrincipalContext.

1

There are 1 best solutions below

2
On

Try change the base object to OU=UK,OU=FR,DC=dc,DC=sys.... it might work,

Please look at the following link for details

http://ldapmaven.com/2011/07/27/mastering-ldapsearch/

EDIT :

It seems like it is not possible, please look at the following SO link,

LDAP root query syntax to search more than one specific OU