Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Searching for users across multiple Active Directory domains

I'm using the System.DirectoryServices.AccountManagement to provide user lookup functionality.

The business has several region specific AD domains: AMR, EUR, JPN etc.

The following works for the EUR domain, but doesn't return users from the other domains (naturally):

var context = new PrincipalContext(ContextType.Domain, "mycorp.com", "DC=eur,DC=mycorp,DC=com");

var query = new UserPrincipal(GetContext());

query.Name = "*Bloggs*";

var users = new PrincipalSearcher(query).FindAll().ToList();

However, if I target the entire directory, it doesn't return users from any of the region specific domains:

var context = new PrincipalContext(ContextType.Domain, "mycorp.com", "DC=mycorp,DC=com");

How do I search the entire directory?

Update

Read up on "How Active Directory Searches Work":

http://technet.microsoft.com/en-us/library/cc755809(v=ws.10).aspx

If I suffix the server name with port 3268 it searches against the Global Catalog:

var context = new PrincipalContext(ContextType.Domain, "mycorp.com:3268", "DC=mycorp,DC=com");

However it's very, very slow. Any suggestions on how to improve performance?

like image 367
Robert Morgan Avatar asked Dec 20 '12 08:12

Robert Morgan


People also ask

How do I search for multiple users in Active Directory?

Please go to User List > Add multiple users from Active Directory. Enter the required information to connect the Active Directory and search user query, press "Search" button. Check the boxes next to the users you want to add, then click the "Next" button.

What is Active Directory Lookup?

Searching within Active Directory Domain Services is a matter of finding a Domain Controller (DC), binding to the object where the search should begin in the directory, submitting a query, and processing the results. For more information about the search feature in Active Directory, see: Deciding What to Find.


1 Answers

Queries which have initial wildcards (*Bloggs*) will be slow unless you have a tuple index on the attribute being queries. None of the attributes in AD have this set by default. Better to not do initial wildcards.

like image 181
asgreene Avatar answered Nov 15 '22 19:11

asgreene