Get-ADComputer throwing random error

Welcome Forums General PowerShell Q&A Get-ADComputer throwing random error

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years ago.

  • Author
  • #6309

    Points: 0
    Rank: Member

    by JohnnyLeuthard at 2013-03-25 11:14:25

    I am using the Get-ADComputer cmdlet to get a list of all computer objects in a forest. I wrapped it in a script to grab the properties I needed format the output.
    The problem is it will randomly throw errors. Not always at the same location. I am not sure if it might be an AD permissions issue or something else? I typically get al tease 20,000 results before it bombs out on me...give or take a few thousand.Can anybody give me a little direction as to why this is happening?

    the command I use to launch the script is (see script below)
    Get-Data | Export-Csv -NoTypeInformation "C:\Temp\Testing.csv"

    64-bit Windows 2008 R2 server
    24 GB RAM
    10 GB free space on the volume I am writing to


    This is the error

    Get-ADComputer : The server has returned the following error: invalid enumeration context.
    At line:20 char:23
    + Get-ADComputer < <<< -SearchScope Subtree -ResultSetSize $null -filter * -properties * | select `
    + CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException
    + FullyQualifiedErrorId : The server has returned the following error: invalid
    enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer

    function Get-Data

    #Load the AD modules
    Import-Module ActiveDirectory
    #Queary AD for the following info
    Get-ADComputer -SearchScope Subtree -ResultSetSize $null -filter * -properties * | select `
    @{Name="Domain";Expression={ ($_.DNSHostName -replace "^\w*.\.", "" ).trim()}},
    @{Name="Name";Expression={ ($_.Name).trim()}},
    @{Name="pwdLastSet";Expression={ [datetime]::fromfiletime($_.pwdLastSet)}},
    @{Name="lastLogonTimestamp";Expression={ [datetime]::fromfiletime($_.lastLogonTimestamp)}}

    by compugab at 2013-03-25 11:49:28

    Maybe you try to enumerate to much propertites. Change your Get-ADComputer call to something like this :

    Get-ADComputer -SearchScope Subtree -ResultSetSize $null -filter * -properties DNSHostName,CanonicalName,pwdLastSet,LastLogonTimestamp

    by JohnnyLeuthard at 2013-03-25 12:24:38

    The problem is I need to have one column that has the domain name so I am grabbing it from the DNSHostname and if I put that in with the properties I get an error . I can try that as a test though and see what happens.

    by JohnnyLeuthard at 2013-03-25 13:04:07

    Now that I walked away from my computer for a bit and come back fresh I realized I can still use my select statement and also format and parse the data but rather than pulling -properties * just pull the properties I need. I ran it without select and I am about 5-6 thousand past the oint where it usually bombs out and gives that error. I will update this thread when it finished running.

    Thanks for such a quick response!?

    by JohnnyLeuthard at 2013-03-25 13:18:55

    Right after I sent this I bombed again LOL but it did get a Little further. 🙂

    So maybe it's something to do with memory? I'm not 100% sure how it is treating this since it's one lone command.
    even though it is passing it across the pipeline and then out to a CSV is it still storing the data in memory and once the buffer fills up it dies?
    If it is keeping everything in memory maybe if i could step through and write a few lines and then clear it?

    On thing I found through Google (my best friend) is someone saying to use the -resultspageSize and set it to something like 10?

The topic ‘Get-ADComputer throwing random error’ is closed to new replies.