Getting More Than 1000 Active Directory Results

by Oct 29, 2013

By default, Active Directory returns only the first 1000 search results when you use an ADSISearcher. This is a security mechanism designed to prevent unspecific LDAP queries from causing domain controller load.

If you do need all search results and know that it will be more than 1000, make sure you set PageSize to 1000. This way, ADSISearcher returns search results in chunks of 1000 elements.

This query would return all user accounts in your domain (you may want to talk to your domain administrator before you actually run this query):

$searcher = [ADSISearcher]"sAMAccountType=$(0x30000000)"

# get all results, do not stop at 1000 results
$searcher.PageSize = 1000

$searcher.FindAll() | 
  ForEach-Object { $_.GetDirectoryEntry() } | 
  Select-Object -Property * |

Twitter This Tip! ReTweet this Tip!