Powershell script - LDAP - PageSize Function


I'm running a script that browse my LDAP. It has worked fine for a long time but yesterday I've been faced to a strange issue.

Some objects were not fetch by the query.
To correct this I was forced to change the PageSize from 1000 to 500.

I don't know why and send a request here if someone could explain me why this pagesize stop to work as requested ?

Thx in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan McFaddenSystems EngineerCommented:
A little more info about the script would be helpful.  Are you using the "System.DirectoryServices.DirectorySearcher" class?  If so, are you using the defaults for the properties on the object you created?

Some possibly useful links:



This blog has a lot of useful examples:  http://www.jaapbrasser.com/

SybuxAuthor Commented:
woops, sorry I missed the code :)

$query = New-Object System.DirectoryServices.DirectorySearcher($edir)
$query.PageSize = 500
$objClass = $query.findall()

Open in new window

Thx for the link but I've already read them via google but it doesn't help me to understand why with pagesize of 1000 not all records are fetched.
Dan McFaddenSystems EngineerCommented:
It would appear that you were trying to return more than the server-side limit of objects.  That implies that you directory object count is above 1000.  By lowering the PageSize you allowed the scripting to grab 500 objects (which is less than the default server-side limit of 1000) then to go back and get the next 500, and so on.  Allowing your script to grab more than the server limit.

This is in the MSDN docs at:  http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.aspx ... check the Remarks near the bottom of the page.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.