Get users from a group in Active Directory

  • Thread starter Thread starter m z via .NET 247
  • Start date Start date
M

m z via .NET 247

Hi All,

I am trying to get a list of users that belong to a group in Active Directory.

Somehow I think I need to use the DirectorySearcher as follows:

DirectorySearcher searcher = new DirectorySearcher(DomainPath);
searcher.Filter = ????
searcher.FindAll();

What do I need to specify in the Filter in order to retrieve the users that are contained in a group?
The MS documentation only tells you how to add users to a group but not how to get them.

Thanks a lot for your help.
 
I am trying to get a list of users that belong to a group in Active Directory.
Somehow I think I need to use the DirectorySearcher as follows:

No need to do this, no.

Just bind to the group in question and examine its "member" property:

DirectoryEntry deGroup = new
DirectoryEntry("LDAP://cn=MyGroup,ou=SomeOU,dc=Fabrikam,dc=com");

foreach(object oMember in deGroup.Properties["member"])
{
Console.WriteLine(oMember.ToString());
}

The "member" property contains a list of DN's of all the members of
that group, e.g. something in the format of
CN=John Doe,CN=Users,dc=Fabrikam,dc=com
CN=Jane Doe,CN=Users,dc=Fabrikam,dc=com

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top