我试图让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
}但是它只返回前1000行。如何在不使用DirectorySearcher的情况下检索所有用户。谢谢。
发布于 2015-11-20 11:24:29
我认为如果不使用DirectorySearcher.,你就无法做到这一点。
代码片段-
// set the PageSize on the underlying DirectorySearcher to get all entries
((DirectorySearcher)search.GetUnderlyingSearcher()).PageSize = 1000;还请参见If an OU contains 3000 users, how to use DirectorySearcher to find all of them?
发布于 2015-11-20 11:30:57
您需要获取基础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
}
}发布于 2019-01-07 16:38:17
您可以:
((DirectorySearcher)myPrincipalSearcher.GetUnderlyingSearcher()).SizeLimit = 20;https://stackoverflow.com/questions/33824785
复制相似问题