1

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.

PineCone
  • 2,193
  • 12
  • 37
  • 78

1 Answers1

0

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

Community
  • 1
  • 1
Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42
  • I am afraid this hasn't worked when I tried before and gave following error: System.DirectoryServices.AccountManagement.PrincipalOperationException was unhandled by user code InnerException: System.DirectoryServices.DirectoryServicesCOMException Message=There is no such object on the server. – PineCone Oct 15 '13 at 11:47
  • Actually taking off the OU completely searched against entire AD. That worked for searching usernames against all users in AD. – PineCone Oct 15 '13 at 14:45