Reading ldap group member from c#

78lro picture 78lro · Jan 19, 2009 · Viewed 8.1k times · Source

I have this code to connect to Active Directory and get all the groups that exist, it works and returns all the groups in results :

DirectoryEntry dirEnt = new DirectoryEntry();

using (DirectorySearcher srch = new DirectorySearcher(dirEnt, "(objectClass=Group)"))
            {
                srch.PageSize = 1000;
                SearchResultCollection results = srch.FindAll();
            }

I now want to return users of a specific group i.e. Administrators, how would I go about this?

I had tried changing (objectClass=Group) to (objectClass=Group)(cn=admin) but then it returns no results.

All the best

Answer

Turnkey picture Turnkey · Jan 19, 2009

Here's a reference about how to in Active Directory:

Howto: (Almost) Everything In Active Directory via C#