473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Get users from a group in Active Directory

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
2 16579
>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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mark | last post by:
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...
2
by: John | last post by:
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...
7
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
1
by: Rod | last post by:
We've implemented forms authentication with Active Directory. We're slowly working on converting our Crystal Reports' reports from a VB6 application into Crystal Reports for .NET in our ASP.NET...
3
by: Luis Esteban Valencia | last post by:
Hello gusys, Is it possible to make my asp.net application add users to the AD , I also want to be able to delete users, modify their information, everything through a website. Thanks for the...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
2
by: m z via .NET 247 | last post by:
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...
6
by: Mr Newbie | last post by:
Hi, Im in a situation where I need to restrict users, but I dont have access or wont be allowed access to manage groups in the domain. How can I restrict access is this case ? -- Best...
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.