开发者

DirectorySearcher not searching entire directory [duplicate]

This question already has an answer here: Can I get more than 1000 records from a DirectorySearcher? (1 answer) Closed 3 years ago.

I'm using System.DirectoryServices.DirectorySearcher for traversing Active Directory for users. In most cases, this works fine. The code is pretty much as follows:

Ldapconnection conn = CreateConnection(.开发者_高级运维..);
System.DirectoryServices.DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher();
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;

foreach (System.DirectoryServices.SearchResult result in searcher.FindAll()) {
}

For some reason, this doesn't always traverse the tree completely. If I specify the searchroot to point at a missing subtree, it does import that subtree.

Am I missing something?


Is it stopping at 1000 users? I believe AD is setup by default to only return 1000 objects.


If the SearchResultCollection's count is 1000 in the cases that you experience the problematic behavior, try setting the PageSize property on the DirectorySearcher to 1000.

Ldapconnection conn = CreateConnection(...); 
DirectorySearcher searcher = new System.DirectoryServices.DirectorySearcher();
searcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
searcher.PageSize = 1000;

foreach (System.DirectoryServices.SearchResult result in searcher.FindAll()) { } 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜