title: How to get all members of a local WinNT group?
body: <p>When I retrieve members of a local WinNT group, someway somehow not <em>all</em> members are returned. I do add:</p>
  
  <ul>
  <li>Active Directory users</li>
  <li>Active Directory groups</li>
  </ul>
  
  <p>Both successful (see picture), but <em>only</em> the users show up afterwards.</p>
  
  <p><img src="https://i.stack.imgur.com/pXMFZ.png" alt="enter image description here"></p>
  
  <p>Question is:</p>
  
  <ul>
  <li>What happens to added groups?</li>
  <li>See last method in code sample 'GetMembers()'</li>
  <li>Is this a known issue?</li>
  <li>Any workaround available?</li>
  </ul>
  
  <p>Many thanks!!</p>
  
  <pre><code>string _domainName = @"MYDOMAIN";
  string _basePath = @"WinNT://MYDOMAIN/myserver";
  string _userName = @"MYDOMAIN\SvcAccount";
  string _password = @"********";
  
  void Main()
  {
     CreateGroup("lg_TestGroup");
     AddMember("lg_TestGroup", @"m.y.username");
     AddMember("lg_TestGroup", @"Test_DomainGroup");
  
     GetMembers("lg_TestGroup");
  }
  
  // Method added for reference.
  void CreateGroup(string accountName)
  {
     using (DirectoryEntry rootEntry = new DirectoryEntry(_basePath, _userName, _password))
     {
        DirectoryEntry newEntry = rootEntry.Children.Add(accountName, "group");
          newEntry.CommitChanges();
     }
  }
  
  // Add Active Directory member to the local group.
  void AddMember(string groupAccountName, string userName)
  {
      string path = string.Format(@"{0}/{1}", _basePath, groupAccountName);
      using (DirectoryEntry entry = new DirectoryEntry(path, _userName, _password))
      {
          userName = string.Format("WinNT://{0}/{1}", _domainName, userName);
        entry.Invoke("Add", new object[] { userName });
          entry.CommitChanges();
      }
  }
  
  // Get all members of the local group.
  void GetMembers(string groupAccountName)
  {
      string path = string.Format(@"{0}/{1}", _basePath, groupAccountName);
     using (DirectoryEntry entry = new DirectoryEntry(path, _userName, _password))
     {
        foreach (object member in (IEnumerable) entry.Invoke("Members"))
        {
           using (DirectoryEntry memberEntry = new DirectoryEntry(member))
           {
              string accountName = memberEntry.Path.Replace(string.Format("WinNT://{0}/", _domainName), string.Format(@"{0}\", _domainName));
              Console.WriteLine("- " + accountName); // No groups displayed...
           }
        }
     }
  }
  </code></pre>
  
  <p><strong>Update #1</strong>
  The sequence of the group members seems to be essential. As soon as the enumerator in <em>GetMembers()</em> stumbles on an Active Directory group, the remaining items are not displayed either. So if 'Test_DomainGroup' is listed first in this example, <em>GetMembers()</em> does not display anything at all.</p>