Author Posts

March 21, 2016 at 7:56 pm

Greetings,
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?
Thanks
David Z

March 22, 2016 at 7:52 am

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
$ADSearchResults

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

(&(!(LegacyExchangeDN=*))(objectClass=contact))

Michael

March 22, 2016 at 3:17 pm

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?

March 22, 2016 at 11:44 pm

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.

Michael

March 29, 2016 at 3:21 pm

Thanks – that's probably it. Pity you can't set it greater than 120 seconds.

March 30, 2016 at 1:48 am

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
$searcher.ServerTimeLimit 

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

Or better still, in the ISE type

$searcher.

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

Michael