[英]Can I get more than 1000 records from a PrincipalSearcher?
I am trying to get all users from Active Directory using code: 我正在尝试使用代码从Active Directory中获取所有用户:
PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password);
UserPrincipal u = new UserPrincipal(ad) {Name = "*"};
PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };
foreach (var principal in search.FindAll())
{
//do something
}
But it returns only first 1000 rows. 但是它仅返回前1000行。 How I can retrieve All users and without using DirectorySearcher.
如何在不使用DirectorySearcher的情况下检索所有用户。 Thanks.
谢谢。
I don't think you will be able to do that without using DirectorySearcher . 我认为如果不使用DirectorySearcher ,您将无法做到这一点。
Code snippet - 代码段-
// set the PageSize on the underlying DirectorySearcher to get all entries
((DirectorySearcher)search.GetUnderlyingSearcher()).PageSize = 1000;
Also see If an OU contains 3000 users, how to use DirectorySearcher to find all of them? 另请参阅如果一个OU包含3000个用户,如何使用DirectorySearcher查找所有用户?
You need to get the underlying DirectorySearcher
and set the PageSize
property on it: 您需要获取基础的
DirectorySearcher
并在其上设置PageSize
属性:
using (PrincipalContext ad = new PrincipalContext(contextType, adserviceName, adContext, ContextOptions.SimpleBind, username, password))
{
UserPrincipal u = new UserPrincipal(ad) {Name = "*"};
PrincipalSearcher search = new PrincipalSearcher { QueryFilter = u };
// get the underlying "DirectorySearcher"
DirectorySearcher ds = search.GetUnderlyingSearcher() as DirectorySearcher;
if(ds != null)
{
// set the PageSize, enabling paged searches
ds.PageSize = 500;
}
foreach (var principal in search.FindAll())
{
//do something
}
}
您可以:
((DirectorySearcher)myPrincipalSearcher.GetUnderlyingSearcher()).SizeLimit = 20;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.