Active directory: Get users associated with groups

M

Mark

Hi, can anyone please tell me (Given a group name) how I can retrieve just
those users associated with that group using Active Directory using LDAP??

I am using the code below with not much luck

Code:
DirectoryEntry entry = new DirectoryEntry("LDAP://" +
Domain,"LoginUser","Password");
DirectorySearcher Dsearch = new DirectorySearcher(entry);
Dsearch.Filter = "objectCategory =All users"; // All users is a group in AD

TIA
Mark
 
M

Mark

Thanks Jakob, I will give this a try
Regards
Mark
Jakob Christensen said:
Try using "LDAP://OU=All users,DC=Domain".

HTH, Jakob.


Mark said:
Hi, can anyone please tell me (Given a group name) how I can retrieve just
those users associated with that group using Active Directory using LDAP??

I am using the code below with not much luck

Code:
DirectoryEntry entry = new DirectoryEntry("LDAP://" +
Domain,"LoginUser","Password");
DirectorySearcher Dsearch = new DirectorySearcher(entry);
Dsearch.Filter = "objectCategory =All users"; // All users is a group in AD

TIA
Mark
 
M

Marc Scheuner [MVP ADSI]

Hi, can anyone please tell me (Given a group name) how I can retrieve just
those users associated with that group using Active Directory using LDAP??

Insepect the user's "memberOf" property

DirectoryEntry deUser = new DirectoryEntry("LDAP://......");

foreach(string sGroupName in deUser.Properties["memberOf"])
{
Console.WriteLine(sGroupName);
}

This is the easy way of doing it - it will *NOT* show you the user's
"primary group", nor any nested groups. For those you'd need to
inspect the user object's "tokenGroups" attribute (which is a
collection of SID's), and then resolve those SIDs to group names.

Check out microsoft.public.adsi.general - there have been several
posts on how to read the full group membership by means of
"tokenGroups".

HTH
Marc

================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 

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

Top