This should not be this hard. I found examples everywhere. All failed until I found the post here: http://forums.asp.net/p/1015907/1365445.aspx
I adapted that code slightly to make it a bit more effecient, the result is below.
///
/// This returns a list of all the users in the goup given the fqdn.
///
/// Fully Qualified Domain Name. Example: mydomain.com, or mydomain.local
/// Group name to enumerate. Example: Domain Admins
///
public static List GetUsers(string fqdn, string group)
{
List users = new List();
DirectoryEntry entry = new DirectoryEntry(string.Format("LDAP://{0}", fqdn));
System.DirectoryServices.DirectorySearcher mySearcher = new System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("CN=" + group);
mySearcher.PropertiesToLoad.Add("member");
try
{
SearchResult result = mySearcher.FindOne();
int propertyCount = result.Properties["member"].Count;
String dn;
int equalsIndex, commaIndex;
for (int propertyCounter = 0; propertyCounter < propertyCount;
propertyCounter++)
{
dn = (String)result.Properties["member"][propertyCounter];
users.Add(dn);
}
}
catch (Exception ex)
{
throw new Exception(string.Format("Error enumerating user names of group '{0}', error: {1}", group, ex.Message));
}
return users;
}
7f0d7a4f-b36a-4d44-bddd-fdf43b753cf8|0|.0