AdsiSearch limit to 1000

This topic contains 7 replies, has 5 voices, and was last updated by Profile photo of Mark Mark 1 year, 2 months ago.

  • Author
    Posts
  • #31389
    Profile photo of Arestas
    Arestas
    Participant

    Hello all,
    Have the following adsiSearch to get all users
    $Users = ([adsisearcher]"(&(objectClass=person)(objectClass=user))").FindAll().Properties

    Problem is that max i can get is 1000 Users and i know theres a lot more.

    So my question would be. How can i get all the users from AD using AdsiSearch?

    Regards,

    Arestas

  • #31393
    Profile photo of Mike Eyler
    Mike Eyler
    Participant

    Any specific reason you are using adsisearcher?

    What about using Get-ADUser?

  • #31398
    Profile photo of Peter Jurgens
    Peter Jurgens
    Participant

    With Get-ADUser you will only get 1000 results by default as well. You would need to use the -ResultSize parameter of Get-ADUser to increase the amount of results to be returned. For ADSI, modify your code like so:

    $Searcher = [adsisearcher]"(&(objectClass=person)(objectClass=user))"
    $Searcher.SizeLimit = 10000
    $Results = $Searcher.FindAll()

  • #31404
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    The 1000 limit is imposed by AD – you'll see the same thing in the GUI tools. As stated above set the Sizelimit property to a sensible value.

    I would recommend using the PowerShell cmdlets over [adsisearcher]

  • #31406
    Profile photo of Arestas
    Arestas
    Participant

    Well,
    Cant connect to AD using Get-ADuser. i think its the firewall in the way. Using adisearch i can.

  • #31407
    Profile photo of Arestas
    Arestas
    Participant

    Using
    $Searcher = [adsisearcher]"(&(objectClass=person)(objectClass=user))"
    $Searcher.SizeLimit = 10000
    $Results = $Searcher.FindAll().properties
    $Result.count

    it returns 1000. So apparently it doesn't work.

  • #31409
    Profile photo of Arestas
    Arestas
    Participant

    Hello
    Used this and is working. Tks all for the precious help.

    $a = [adsisearcher]"(&(objectClass=person)(objectClass=user))"
    $a.SearchRoot=$root
    $a.PageSize = 5000
    $a.PropertiesToLoad.add("samaccountname")| Out-Null
    $a.PropertiesToLoad.add("distinguishedname")| Out-Null
    $results = $a.findall()

  • #31412
    Profile photo of Mark
    Mark
    Participant

    Using $Searcher.SizeLimit = 10000 will result in up to 10,000 object being returned.

    Using $Searcher.PageSize = (any non-zero value) will fully return the results.

    Without setting PageSize, the default is to perform a non-paged LDAP query which will return either 1000 or 1500, depending on of the AD environment was built using W2000 or 2003+

    The PageSize value is used behind the scenes to control how LDAP results are batched up on the DC and passed back to the client. The larger the number, the bigger each batch, which in not a good thing. Larger batches put more load and memory allocation on the DC. Setting 1000 thru 2500 should do.

You must be logged in to reply to this topic.