AD 中 查询 1000条限制问题
- MaxPageSize -此值控制的最大独立的每个返回的对象的大小对单个搜索结果中返回的对象数。要执行的搜索的结果可能超过此数目的对象,客户端必须指定分页的搜索控件。这是在不大于MaxPageSize值的组中返回的结果进行分组。总之, MaxPageSize控制在单个搜索结果中返回的对象的数目。
默认值: 1000
代码中设置一下 PageSize 即可,
参考代码:
//得到Ad中所有用户
public static SearchResultCollection GetAllUsers(string adPath, string adMIN, string adPWD)
{
try
{
DirectoryEntry entry = new DirectoryEntry(adPath, adMIN, adPWD, DefaultAuthenticationType);
// DirectoryEntry entry = new DirectoryEntry(ADPath, ADMIN, AdPWD, DefaultAuthenticationType);
DirectorySearcher directorySearch = new DirectorySearcher(entry);
// LDAP://sensen.com/CN=001216,OU=User,OU=JR,DC=sensen,DC=com
directorySearch.Filter = "(&(objectClass=user))";
// directorySearch.Filter = "(&(objectClass=organizationalUnit)(ou=JR))";
directorySearch.Sort.PropertyName = "cn";
directorySearch.SearchScope = SearchScope.Subtree;
directorySearch.PageSize = 5000;
SearchResultCollection results = directorySearch.FindAll();
if (results != null)
{
return results;
}
else
{
return null;
}
}
catch (Exception ex)
{
return null;
}
}
这个问题在微软的网站已经给出了解决方案 :http://support.microsoft.com/kb/315071