Active Directory嵌套组

Ric*_*ood 10 c# active-directory

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

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

mar*_*c_s 15

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

基本上,您可以定义域上下文并轻松查找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);
}
Run Code Online (Sandbox Code Playgroud)

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


Mar*_*eed -1

假设您使用 ActiveDirectory 的 LDAP 视图,您要查找的属性称为“objectClass”。我相信,一个组的 objectClass 为“groupOfNames”;可能是“团体”。或者,只需查看对象是否有任何“成员”,无论对象类如何,如果有,则假设它是某种组并递归。