3

如何使用子容器(子 OU)防止查询特定 OU 中的子容器对象?

澄清一下,我不想在结果集中包含子 OU(子容器)中的用户对象。

给定类似于另一个stackoverflow帖子上的代码,例如:

// create a principal object representation to describe
// what will be searched 
UserPrincipal user = new UserPrincipal(adPrincipalContext);

// define the properties of the search (this can use wildcards)
user.Enabled = false;
user.Name = "user*";

// create a principal searcher for running a search operation
PrincipalSearcher pS = new PrincipalSearcher();

// assign the query filter property for the principal object 
// you created
// you can also pass the user principal in the 
// PrincipalSearcher constructor
pS.QueryFilter = user;

// run the query
PrincipalSearchResult<Principal> results = pS.FindAll();

Console.WriteLine("Disabled accounts starting with a name of 'user':");
foreach (Principal result in results)
{
    Console.WriteLine("name: {0}", result.Name);
}

谢谢,

胜利者

4

1 回答 1

3

不幸的是,这个(和其他一些)特性在PrincipalSearcher课堂上是不直接可见的。

您需要“深入”到底层DirectorySearcher来设置这样的选项(例如页面大小):

DirectorySearcher ds = pS.GetUnderlyingSearcher() as DirectorySearcher;

if(ds != null)
{
   ds.SearchScope = SearchScope.Base;  // or SearchScope.OneLevel - your pick
}
于 2011-09-02T14:30:10.703 回答