【发布时间】:2010-06-03 00:19:54
【问题描述】:
我正在尝试使用 .NET 获取 AD 组中的组列表。
例如,我有一个名为 TestGroup 的组,在该组内我有组 DomainAdministrators。
使用下面的代码,我可以获取所有用户,包括来自 DomainAdministrators 组的用户,但不能获取该组本身。
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DomainName");
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "TestGroup");
ArrayList members = new ArrayList();
if (grp != null)
{
foreach (Principal p in grp.GetMembers(true))
{
members.Add(p.Name)
}
}
grp.Dispose();
ctx.Dispose();
我尝试了 GetGroups 而不是 GetMembers,但这并没有返回任何内容。如何返回组中的组?
【问题讨论】:
-
查看
GetMembers的值。GetMembers返回属于组的 AD 对象。GetGroups是当前 AD 对象所属的组成员。
标签: c# .net active-directory