0

我正在尝试查找 AD 查询来测试用户 A 是否属于 B 组。

用户A是A组的成员,A组是B组的成员;因此,用户 A 实际上是组 B 的成员。

我曾尝试查看来自http://msdn.microsoft.com/en-us/library/aa746475%28VS.85%29.aspx的信息,但这看起来像是从用户开始搜索并下降。我需要能够从 Group 开始并爬取子对象。

4

1 回答 1

0

如果您使用 .NET 3.5 及更高版本,并使用 VB.NET 或 C# 作为您的编程语言,您应该检查System.DirectoryServices.AccountManagement(S.DS.AM) 命名空间。在这里阅读所有相关信息:

基本上,您可以定义域上下文并在 AD 中轻松找到用户和/或组:

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

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   // find the group in question
   GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "YourGroupNameHere");

   if(group != null)
   {
      bool isUserMemberOfThatGroup = user.IsMemberOf(group);
   }
}

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

于 2012-05-30T20:35:37.157 回答