Get-ADComputer throwing random error

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
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 <br> + CategoryInfo : NotSpecified: (:) [Get-ADComputer], ADException<br> + FullyQualifiedErrorId : The server has returned the following error: invalid <br> enumeration context.,Microsoft.ActiveDirectory.Management.Commands.GetADComputer<br>[/quote]<br><br><br><br><br><br><br><code><br>function Get-Data<br>{<br> &#91;CmdletBinding()&#93;<br> Param<br> (<br><br> )<br> begin<br> {<br> #Load the AD modules<br> Import-Module ActiveDirectory<br> }#begin<br> Process<br> {<br> #Queary AD for the following info<br> Get-ADComputer -SearchScope Subtree -ResultSetSize $null -filter * -properties * | select
@{Name=“Domain”;Expression={ ($.DNSHostName -replace “^\w*.&#46;”, “” ).trim()}},
@{Name=“Name”;Expression={ ($
@{Name=“pwdLastSet”;Expression={ [datetime]::fromfiletime($
@{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. :slight_smile:

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?