By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Get users from a group in Active Directory

P: n/a
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.

--------------------------------
From: m z

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>PytcyFKMyUa+fsjLi5MWLQ==</Id>
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
>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
Jul 21 '05 #2

P: n/a
>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
Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.