user502084
user502084

Reputation: 11

Getting users list from an AD Group

I have a domain and I am not aware of the domain server name or IPaddress, all I know is just the domain name. A group created under this domain. The users added to this domain belong to different domains. I have to get the list of users, irrespective of their domain, added to that group and show it in a list box. I have to do this in C# web application.

Please direct me.

Upvotes: 1

Views: 1701

Answers (1)

marc_s
marc_s

Reputation: 755371

Using .NET 3.5 and the System.DirectoryServices.AccountManagement namespace, you should be able to write something like:

// create domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// fetch your group
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "groupname");

// enumerate over the group's members
foreach (Principal p in group.Members)
{
   Console.WriteLine("Principal '{0}', type '{1}'", p.Name, p.StructuralObjectClass);
}

This should list all the member's of that group (users and groups).

Upvotes: 2

Related Questions