Searching AD: BadEnumeration: More data is available

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Michael Maher Michael Maher 8 months, 2 weeks ago.

  • Author
    Posts
  • #36809
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    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

  • #36872
    Profile photo of Michael Maher
    Michael Maher
    Participant

    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

  • #36891
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

    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?

  • #36894
    Profile photo of Michael Maher
    Michael Maher
    Participant

    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

  • #37068
    Profile photo of David Zemdegs
    David Zemdegs
    Participant

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

  • #37075
    Profile photo of Michael Maher
    Michael Maher
    Participant

    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

You must be logged in to reply to this topic.