Skip to content

Instantly share code, notes, and snippets.

@rstackhouse
Created August 4, 2011 13:40
Show Gist options
  • Save rstackhouse/1125170 to your computer and use it in GitHub Desktop.
Save rstackhouse/1125170 to your computer and use it in GitHub Desktop.
List users in group in C#
using(DirectoryEntry d = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer"))
{
using(DirectoryEntry g = d.Children.Find("Administrators", "group"))
{
object members = g.Invoke("Members", null);
foreach(object member in (IEnumerable)members)
{
DirectoryEntry x = new DirectoryEntry(member);
Console.Out.WriteLine(x.Name);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment