Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If your AD isn't too big, and you're on .NET 3.5 or up (which I assume, since you're using VS2010), you should be able to write something like:</p> <pre><code>// create a domain context for your default domain PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // define a "query-by-example" to search for Principal searchExample = new UserPrincipal(ctx); // define the principal searcher, based on that example principal PrincipalSearcher ps = new PrincipalSearcher(searchExample); // loop over all principals found by the searcher foreach(Principal p in ps.FindAll()) { // do whatever you want to do with the principals Console.WriteLine("Type: {0} / Name: {1}", p.StructuralObjectClass, p.Name); } </code></pre> <p><strong>PS:</strong> In order to "find your LDAP", you could have a look at my C#, open-source LDAP browser called <a href="http://adsi.mvps.org/adsi/CSharp/beavertail.html" rel="nofollow noreferrer">BeaverTail</a> - available for free (C#, .NET 1.1 timeframe)</p> <p><img src="https://i.stack.imgur.com/s15t8.png" alt="enter image description here"></p> <p><strong>Update:</strong> if you want to select all users in a specific location (and its sub-containers), you can do this by specifying that "starting point" in your domain context:</p> <pre><code>// create a domain context for your default domain, // starting at a specific location PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "YOURDOMAIN", "OU=Personnel,OU=Users,DC=YourDomain,DC=com"); // define a "query-by-example" to search for Principal searchExample = new UserPrincipal(ctx); // define the principal searcher, based on that example principal PrincipalSearcher ps = new PrincipalSearcher(searchExample); // loop over all principals found by the searcher foreach(Principal p in ps.FindAll()) { UserPrincipal up = (p as UserPrincipal); if(up != null) { // do whatever you want to do with the principals Console.WriteLine("Name: {0} / E-Mail: {1}", up.Name, up.EmailAddress); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload