title: C# - GroupPrincipal.GetMembers(true) - which group?
body: <p>So I'm trying to get something going with enumerating AD group membership recursively. At the moment I have...</p>
  
  <pre><code>PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "mine.domain.com");
  GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "myADGroup");
  if (grp != null)
  {
      foreach (Principal p in grp.GetMembers(true))
      {
          Console.WriteLine(p.Name);
      }
  }
  </code></pre>
  
  <p>This all works great, of course. It lists every user who is a member of the group and all the users who are members of groups nested within, however many nesting levels deep that may be. Which is great.</p>
  
  <p>What I really need is to know <em>what</em> group in this little nesting the user came from.</p>
  
  <pre><code>GRP-MainProject
     -- GRP-Producers
     -- GRP-Artists
       -- UserA
  </code></pre>
  
  <p>Running my current query against GRP-MainProject will return UserA - how should I go about returning the user and the fact that it was GRP-Artists which he inherited membership of GRP-MainProject from?</p>
  
  <p>UserA is a member of about 40 groups or so, in case that matters. <em>Edit - worth mentioning the user could have membership of the group from multiple nested groups.</em></p>
  
  <p>Any thoughts would be appreciated.</p>