I am using System.Security.Principal to identify clients and allow
functionality based on the groups they belong to. In one case I would like
to let them know who can do the function they cannot. How do I list the
members of a group?
Thanks
Tom
Nick - 11 Jul 2007 19:53 GMT
http://www.codeproject.com/dotnet/QueryADwithDotNet.asp
Let's get a list of users belonging to a particular AD group. The code below
shows how to do this:
ArrayList GetADGroupUsers(string groupName)
{ SearchResult result;
DirectorySearcher search = new DirectorySearcher();
search.Filter = String.Format("(cn={0})", groupName);
search.PropertiesToLoad.Add("member");
result = search.FindOne();
ArrayList userNames = new ArrayList();
if (result != null)
{
for (int counter = 0; counter <
result.Properties["member"].Count; counter++)
{
string user = (string)result.Properties["member"][counter];
userNames.Add(user);
}
}
return userNames;
}