Powershell script - LDAP - PageSize Function

Posted on 2014-08-18
Medium Priority
Last Modified: 2014-08-23

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.
Question by:Sybux
  • 2
LVL 29

Expert Comment

by:Dan McFadden
ID: 40269749
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/


Author Comment

ID: 40269755
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.
LVL 29

Accepted Solution

Dan McFadden earned 2000 total points
ID: 40269830
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.


Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Loops Section Overview

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question