A list of people in an active directory group.

  • Thread starter Thread starter newscorrespondent
  • Start date Start date
N

newscorrespondent

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
 
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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top