If an OU contains 3000 users, how to use DirectorySearcher to find all of them?

前端 未结 2 1351
情书的邮戳
情书的邮戳 2020-12-31 19:16

I use this code:

DirectoryEntry objEntry;
DirectorySearcher objSearchEntry;
SearchResultCollection objSearchResult;
string strFilter = \"(&(objectCategor         


        
2条回答
  •  执笔经年
    2020-12-31 19:54

    You need to set the DirectorySearcher.PageSize property to be able to return all the results. For example:

    objSearchEntry.PageSize = 500;
    

    Otherwise the number of items returned will be limited by the limit on the server side, which is 1000 by default. There is also something called SizeLimit, which you can set if you want to explicitly limit the number of returned items. If both SizeLimit and PageSize are 0 (default values) then it will use the server side default SizeLimit. A bit counter-intuitive in my opinion.

    If you want to return all the results, the only way is to set PageSize to a non-zero value and SizeLimit to 0.

提交回复
热议问题