DirectorySearcher not searching entire directory [duplicate]
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()) { }
精彩评论