如何防止在查询特定OU (子OU)时使用子容器对象?
为了清楚起见,我不想在结果集中包含子OU(子容器)中的用户对象。
给出类似于another stackoverflow post上的代码,例如:
// 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);
}谢谢,
维克多
发布于 2011-09-02 22:30:11
不幸的是,这个(和其他一些)特性在PrincipalSearcher类中是不可见的。
你需要“深入”到底层的DirectorySearcher来设置这样的选项(比如页面大小):
DirectorySearcher ds = pS.GetUnderlyingSearcher() as DirectorySearcher;
if(ds != null)
{
ds.SearchScope = SearchScope.Base; // or SearchScope.OneLevel - your pick
}https://stackoverflow.com/questions/7284406
复制相似问题