DirectorySearcher.FindAll() -should have PageSize=1000

When you are calling DirectorySearcher.FindAll() and there is  a chance to have more than 1000 records back, you must set PageSize to non-zero value, preferably 1000. Otherwise only the first 1000 records will be returned and other entries will be missed without any warning.

The names of DirectorySearcher members  and documentation is quite messy. FindAll() method should return ALL records, not the first 1000. Setting PageSize doesn't mean that you get back only single page, but triggers returning of the values into "page size" chunks transparently to you in the background. If you set SizeLimit to a value that is larger than
the server-determined default of 1000 entries, the server-determined default is used.

Thanks to Joe Kaplan's post that finally helped to find solution.

I have a simple program that imported AD users to application database. It was tested and worked fine on a few sites.

However one of our customers complained that some users were missed during import when others were imported successfully. No pattern was found what is the difference between imported and missed user accounts.

After some investigation it was noticed that only 1000 records are returned by DirectorySearcher.FindAll.  Ok, documentation describes DirectorySearcher.SizeLimit with default value is zero, which means to use the server-determined default size limit of 1000 entries. I've changed SizeLimit to 100000, but it didn't help -still only the first 1000 was returned. 
Reading further, I found that the server-determined default is used so SizeLimit is useless, if you expect  big number of results. In a few posts I found how to change the default value on the server, but there were also recommendations not to change server setting, but use paging instead. OK but how to use paging? I've started to search for code examples, expecting that some complicated coding will be required.

Finally  Joe Kaplan's post explains that only code change that required is
PageSize=1000
and all paging will happen in background.

MS should have better  DirectorySearcher documentation and implement background paging by default.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Tuesday, December 20, 2005 7:01 AM
Print

Comments on this entry:

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by JB at 2/8/2006 9:12 PM
Gravatar
Problem solved! Thank you sooooooo much for posting this solution!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Tortured Soul at 7/15/2006 2:35 AM
Gravatar
Bhai u r God. You saved many lives...^:)^

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by TS at 9/7/2006 12:42 PM
Gravatar
Good solution. It helped me fixing search issues in my program.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Leon Zandman at 9/22/2006 3:25 PM
Gravatar
Thanks for your post. It helped me fix my problems. I agree the MSDN docs should be more clear about this issue.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by FTriana at 12/1/2006 4:11 AM
Gravatar
Thank you so much for posting this tip !!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Abinayaa at 4/3/2007 1:57 PM
Gravatar
Thanks !!! Thanks !!! this info has helped me to solve the problem quickly....

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by M4k at 5/29/2007 1:00 AM
Gravatar
THANKS A LOT!!!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Pruthvi at 6/22/2007 3:52 AM
Gravatar
Thanks a lot !!! At last I reached to the information which I wanted. I spent 2 Hrs on google before I reach here.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Aneesh Aravind at 7/27/2007 7:27 AM
Gravatar
I already did that. I have a different issue. My computer gets bogged down when the result set gets to ~ 1800. I set the page size to 1000. I checked the pagefile usage and found that it was more than double of what it usually is.

Did anyone else encounter this issue?

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mow at 11/12/2007 8:58 PM
Gravatar
Try a number greater than 1000 for example 2000....

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by DeLo at 12/17/2007 5:34 AM
Gravatar
Like other responses, I searched for hours on dealing with more than 1000 objects. This did it.. thanx for sharing.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by jl at 1/9/2008 12:36 AM
Gravatar
THANKS!!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Dave at 2/26/2008 12:07 AM
Gravatar
Thanks,Helped me as wel.I was also perplexed by this problem.It saved me a lots of time.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Talat at 7/3/2008 4:04 AM
Gravatar
Thanks, great solution!
I tried many other ways without success.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mahfuz at 8/10/2008 4:20 PM
Gravatar
The solution is working fine for me. Thanks a lot! But it is strange that nobody is complaining about Microsoft for this stupid bug! :|

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Noah at 8/27/2008 8:26 AM
Gravatar
Thanks for this. I'll test this for my customer and see if it works.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Ed Sliman at 9/9/2008 12:16 AM
Gravatar
Ditto for me guys!! Been wrestling with this and finally you have given the answer. Have thousands of groups, but not returning them all. Thanks Again!!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Waseem Al Mustafa at 11/8/2008 7:29 AM
Gravatar
Really ,amazing tip
that was my problem too
thank you very much
waseem

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by GLotsapot at 3/11/2009 6:27 AM
Gravatar
That makes like so much easier. Prior to this, I couldn't find an answer, so I just looped through the alphabet and used that for a LDAP filter [e.g.(samAccountName=a*)]

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by taoboy at 4/14/2009 8:21 PM
Gravatar
thank u for this,u helpe me solve the boring problem !

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by KeeperOfLogic at 6/3/2009 12:54 AM
Gravatar
Thanks, saved me a lot of time. Just a pointer - you need to set them both in order for it to work:
PageSize = 1000;
SizeLimit = 100000;

And I join you on your rant about MS poor documentation. They should be ashamed at themselves. At least it brings visitors to our blogs :)

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Karan at 8/11/2009 7:54 PM
Gravatar
How did you loop to get the 1000+ users

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Michael Freidgeim at 8/12/2009 8:04 AM
Gravatar
Hi Karan,
Example from MSDN "Getting Search Results"
http://msdn.microsoft.com/en-us/library/ms180881.aspx

results = mySearcher.FindAll();

// Iterate through each SearchResult in the SearchResultCollection.
foreach (SearchResult searchResult in results)

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by web development company at 8/14/2009 11:29 AM
Gravatar
Great tip, thanks for mentioning that it was great , I loved it

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by raju datla at 11/4/2009 7:07 PM
Gravatar
you saved many lives. Thank you.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Richard at 1/25/2010 5:12 AM
Gravatar
Thankyou for posting this.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by WCX at 1/27/2010 10:52 AM
Gravatar
It was helpful. Thanks so much!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Mikhail at 12/2/2010 4:01 AM
Gravatar
Thank you! You saved me lot a time.
Without "PageSize=1000" string my program returned only 6002 user records, after adding it - 6057.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Anil at 12/16/2010 12:05 PM
Gravatar
Thanks a lot. Yeah agree with you, MS doesn't have proper documentation for it.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Marcus at 4/28/2011 7:33 AM
Gravatar
Thanks, had the same Problem!

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Constantine at 5/9/2011 9:07 PM
Gravatar
Thanks for posting this. I now know why I was only getting 10,000 results from Active Directory.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Walter at 7/25/2011 9:19 AM
Gravatar
Thank you very much. It's that simple. Just change the value to a different value.

# re: DirectorySearcher.FindAll() -should have PageSize=1000

Left by Anis Achek at 9/26/2011 2:38 AM
Gravatar
Thank you for the tip. Very helpful. I made some tests on my side. Seems the returned results are unlimited each time the specified SizeLimit is greater than or equal to the PageSize. If it's not then the count of the returned records is equal to the value specified in SizeLimit.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910