0
votes

I am getting all the users in specific OUs from a C# code that I wrote. You may see the code below. And I would like to know what is the equivalent LDAP query that I need to make in the Active Directory Users and Computers (ADUC) User Interface (UI) to get the same results (see attached figure).

Thank you for helping. I am quite new with LDAP and Active Directories (AD) and I appreciate any help even if my question is stupid.

C# code:

myDirectoryEntry = new DirectoryEntry("LDAP://subdomain.domain.com/OU=firstou,OU=secondou,OU=thirdou,OU=forthou,OU=fifthou,OU=sixthou,DC=subdomain,DC=domain,DC=com");
                myDirectorySearcher = new DirectorySearcher(myDirectoryEntry);
                myDirectorySearcher.PageSize = 10000;
                myDirectorySearcher.CacheResults = false;
myDirectorySearcher.Filter = "(objectCategory=user)";
myDirectorySearcher.SearchScope = SearchScope.Subtree;
            SearchResultCollection result= myDirectorySearcher.FindAll();

What goes in the ADUC LLDAP filetr UI? Click here for a picture

1
personally you can do this much simpler using PrincipalContext in my opinion and with less code.. do a google search on Getting all Users from AD using PrincipalContext I do this on a daily basis using PrincipalContext - MethodMan
Thanks @MethodMan for your reply. First I will need to find out what is a PrincipalContext :) As I said I am new in AD and LDAP. Secondly I would realy need an answer to my initial question if you have one. - aragorn
I can post something also it's very easy to understand PrincipalContext whether you're new coder or not.. use the debugger to step through the code also MSDN has examples and explanation as well - MethodMan

1 Answers

0
votes

In ADUC, click the 'Browse' button at the top right and browse to the OU you want to search.

Then in the 'Enter LDAP Query' box, put in the same query you are using in your code:

(objectCategory=user)