0

我一直在努力寻找一种查询指定 AD 组成员的好方法。

我在查找组,甚至根据条件查询用户方面没有问题。

目前我有

 PrincipalContext context = new PrincipalContext(ContextType.Domain, _domain, ADServerUser, ADServerPassword);
 UserPrincipal userPrinciple = new UserPrincipal(context);
 userPrinciple.GivenName = "stringToSearchForFirstName";
 userPrinciple.Name = "stringToSearchForUserName";
 userPrinciple.Surname = "stringToSearchForLastName";
 PrincipalSearcher srch = new PrincipalSearcher(new UserPrincipal(context));                    
 srch.QueryFilter = userPrinciple;
 var result = srch.FindAll();

这为我提供了我想要的所有用户,但它不会过滤组。

我可以将 GroupPrincipal 对象与主体搜索一起使用,但我无法过滤掉用户。

我有点想要一种方法,能够同时应用 UserPrincipal 和 GroupPrincipal 来过滤由 Group 和 User 参数返回的结果。

我使用了一个 linq where 子句来尝试进行匹配以查看用户是否在一个组中,但是当我得到所有用户时,查询超时。总的来说是有道理的。

但是,如果我查询该组,我无法使用 principalSearcher 来应用查询。

关于如何做到这一点的任何想法?

4

2 回答 2

2
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, _domain);
// get the AD Group you are wanting to Query
GroupPrincipal group = GroupPrincipal.FindByIdentity("cn=YourGroupname");
foreach(Principal p in group.Members)
{
    //do what ever coding you need to do here            
}
于 2013-02-07T23:12:04.137 回答
1

根据我的研究,我得出的结论是,使用主体对象来过滤组和用户参数是不可能的。我们需要恢复使用对 AD 的查询字符串方法来解决问题。

于 2013-02-17T06:43:04.093 回答