开发者

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 use开发者_如何学JAVArs, 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.


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜