防止 PrimarySearcher 查询 C# 中的子容器对象
如何防止在对具有子容器(子 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);
}
谢谢,
Victor
How can I prevent subcontainer objects in queries to a specific OU with subcontainers (child OU)?
To clarify, I don't want to include user objects in children OUs (subcontainers) in the result set.
Given something like the code on another stackoverflow post for example:
// 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);
}
Thanks,
Victor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这个(以及其他一些)功能在
PrincipalSearcher
类上不直接可见。您需要“深入”底层
DirectorySearcher
来设置如下选项(例如页面大小):Unfortunately, this (and a few other) features aren't visible directly on the
PrincipalSearcher
class.You need to "reach down" to the underlying
DirectorySearcher
to set options like this (and e.g. the page size):