Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're running on .NET 3.5 or newer, 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 GroupPrincipal GroupPrincipal qbeGroup = new GroupPrincipal(ctx); // create your principal searcher passing in the QBE principal PrincipalSearcher srch = new PrincipalSearcher(qbeGroup); // find all matches foreach(var found in srch.FindAll()) { GroupPrincipal foundGroup = found as GroupPrincipal; if(foundGroup != null) { // do whatever you need to do, e.g. put name into a list of strings or something } } </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>When you have a given group, you can easily get all its group members by using:</p> <pre><code>// find the group in question (or load it from e.g. your list) GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere"); // if found.... if (group != null) { // iterate over members foreach (Principal p in group.GetMembers()) { Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName); // do whatever you need to do to those members } } </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