Get all members of a SecurityGroup in AD?

  • Thread starter Thread starter Claus Konrad
  • Start date Start date
C

Claus Konrad

Hi

I've been informed that it is very troublesome to retrive all members in a domain (let's say "ABC"), that is member of a specific SecurityGroup (global or local)? I've been told that one has to loop through every single user in the domain and then ask "Is he member of the securitygroup"? Can this really be true?

What's the best way to retrieve information on who is member of e.g. SecurityGroup "ABC.SecGrp1"?

Thanks!
/Claus
 
What's the best way to retrieve information on who is member of e.g.
SecurityGroup "ABC.SecGrp1"?

There are several ways to do this. I'd suggest posting your message on
microsoft.public.adsi.general where you can take anything Joe Kaplan says as
pretty much definitive... :-)

In the meantime, here's a function which accepts the group as a parameter
and returns a Hashtable of the members of that group:

using System;
using System.Collections;
using System.DirectoryServices;

public static Hashtable GetUsersInGroup(string pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objGroup = null;
object objMembers = null;
Hashtable htblUsers = new Hashtable();

try
{
objADEntry = new DirectoryEntry("WinNT://" + mstrDomain + ",
domain");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
objMembers = objGroup.Invoke("Members");
foreach (object objMember in (IEnumerable)objMembers)
{
DirectoryEntry objUser = new DirectoryEntry(objMember);
htblUsers.Add(objUser.Name, GetObjectProperty(objUser.Name,
"FullName"));
}
return htblUsers;
}
catch (Exception)
{
throw;
}
}
 

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