Active Directory嵌套组

我有一个C#4.0程序,可以检索特定AD组的所有成员。 在此AD组中,包含其他成员的其他AD组。 我需要我的程序来识别它是一个组并检索该组中的成员。

我知道我需要写一个递归程序,但我希望有人可能已经完成了它。 如果没有,有人可以告诉我AD属性属性,以确定该成员是实际的组吗?

由于您使用的是.NET 3.5及更高版本,因此您应该查看System.DirectoryServices.AccountManagement (S.DS.AM)命名空间。 在这里阅读所有相关内容:

  • 管理.NET Framework 3.5中的目录安全性主体
  • System.DirectoryServices.AccountManagement上的MSDN文档

基本上,您可以定义域上下文并轻松查找AD中的用户和/或组。 另外: GroupPrincipal有一个名为GetMembers的方法,它将列出该组的所有成员 – 可选地,它将以递归方式为您执行此操作!

 // set up domain context PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // find the group you're interested in GroupPrincipal myGroup = GroupPrincipal.FindByIdentity(ctx, "SomeGroup"); // if you found it - get its members if (myGroup != null) { // if your call the GetMembers, you can optionally specify a "Recursive" flag - done here var allMembers = myGroup.GetMembers(true); } 

新的S.DS.AM使得在AD中与用户和群组玩起来非常容易!

假设您正在将LDAP视图用于ActiveDirectory,您正在寻找的属性称为“objectClass”。 我相信一个小组会出现一个objectClass为“groupOfNames”的小组; 可能是“团体”。 或者,只要查看对象是否具有任何“成员”,无论对象类如何,如果确实如此,则假设它是某种组并递归。