Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a <code>PrincipalSearcher</code> and a "query-by-example" principal to do your searching:</p> <pre><code>// create your domain context PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // define a "query-by-example" principal - here, we search for a UserPrincipal // and with the first name (GivenName) of "Bruce" UserPrincipal qbeUser = new UserPrincipal(ctx); qbeUser.GivenName = "Bruce"; // create your principal searcher passing in the QBE principal PrincipalSearcher srch = new PrincipalSearcher(qbeUser); // find all matches foreach(var found in srch.FindAll()) { // do whatever here - "found" is of type "Principal" - it could be user, group, computer..... } </code></pre> <p>If you haven't already - absolutely read the MSDN article <a href="http://msdn.microsoft.com/en-us/magazine/cc135979.aspx" rel="noreferrer">Managing Directory Security Principals in the .NET Framework 3.5</a> which shows nicely how to make the best use of the new features in <code>System.DirectoryServices.AccountManagement</code></p> <p><strong>Update:</strong></p> <p>Of course, depending on your need, you might want to specify other properties on that "query-by-example" user principal you create:</p> <ul> <li><code>Surname</code> (or last name)</li> <li><code>DisplayName</code> (typically: first name + space + last name)</li> <li><code>SAM Account Name</code> - your Windows/AD account name</li> <li><code>User Principal Name</code> - your "username@yourcompany.com" style name</li> </ul> <p>You can specify any of the properties on the <code>UserPrincipal</code> and use those as "query-by-example" for your <code>PrincipalSearcher</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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