Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I came up with something similar to marc_s using the <code>System.DirectoryServices.AccountManagement</code> namespace:</p> <pre><code>PrincipalContext context = new PrincipalContext(ContextType.Domain); GroupPrincipal queryPrincipal = new GroupPrincipal(context); using (PrincipalSearcher searcher = new PrincipalSearcher(queryPrincipal)) using (PrincipalSearchResult&lt;Principal&gt; allPrincipals = searcher.FindAll()) foreach (GroupPrincipal groupPrincipal in allPrincipals.OfType&lt;GroupPrincipal&gt;()) { // Process group... foreach (UserPrincipal userPrincipal in groupPrincipal.Members.OfType&lt;UserPrincipal&gt;()) { // Process group member... } } </code></pre> <p>The <a href="http://msdn.microsoft.com/library/system.directoryservices.accountmanagement.userprincipal.aspx" rel="nofollow"><code>UserPrincipal</code> class</a> doesn't appear to expose any members that would allow you to determine if a user is and/or has a manager, but you can still do it by obtaining the <a href="http://msdn.microsoft.com/library/system.directoryservices.directoryentry.aspx" rel="nofollow"><code>DirectoryEntry</code></a> for the user:</p> <pre><code>DirectoryEntry userEntry = userPrincipal.GetUnderlyingObject() as DirectoryEntry; if (userEntry != null) { bool isManager = userEntry.Properties["directReports"].Count &gt; 0; bool isManaged = userEntry.Properties["manager"].Count &gt; 0; // Perform further processing... } </code></pre> <p>You'll need some additional logic, though, to determine if the user is a manager in the group you're currently looking at, rather than some other group. Maybe check the <code>directReports</code> property to see if any of the users contained within are members of the current group.</p>
 

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