Searching AD: BadEnumeration: More data is available

I’m trying to run this:

$searcher = New-Object DirectoryServices.DirectorySearcher
$searcher.Filter = ‘(&(!(LegacyExchangeDN=*))(objectClass=contact))’
$searcher.pageSize = 1000
$ADSearchResults = $searcher.FindAll() | select @{n=‘DistinguishedName’;e={$_.Properties.distinguishedname}}

and I get an error id of ‘BadEnumeration’ and the text:
An error occurred while enumerating through a collection: More data is available.

Can’t find any info on this in google.
Any ideas?
David Z

I ran this code David, it worked fine for me.

The format of the data retrieved by your query by be causing the error. Maybe a special character?

Could you see if it returns any result?

This is the same code except limited to first result (-First 1)

$searcher = New-Object DirectoryServices.DirectorySearcher
$searcher.Filter = '(&(!(LegacyExchangeDN=*))(objectClass=contact))'
$searcher.pageSize = 1000
$ADSearchResults = $searcher.FindAll() | select @{n='DistinguishedName';e={$_.Properties.distinguishedname}} -First 1

Does it work in Active Directory Administrative Center? Global Search, Convert to LDAP Radio Button and then paste in



I just ran it stand alone and it worked. I also did the ldap query in ADAC and that gave me a timeout. So it seems to be failing intermittently which would not be explained by bad data.
We have around 130,000 contacts so maybe it is sometimes just too much to handle?

Hi David,

There is a DirectorySearcher.ServerTimeLimit property which defaults to 120 seconds. I wonder if your successful results are coming in just under that time span.


Thanks - that’s probably it. Pity you can’t set it greater than 120 seconds.

Hi David,

You can set it in teh same manner you set the page size.

# To see existing value. -1 means default of 120 seconds

# To set a new value
$searcher.ServerTimeLimit = 180

Or better still, in the ISE type


Then hit Ctrl and Space to see the other properties you can tweak to get your search working.