WriteDebugStream during AD Inventory collection

I am a domain administrator and was running the following script to collect assorted properties of Users in our 3 domain forest.

    $creds = Get-Credential
#dump all User to a variable
    $AllUsers = ForEach ($domain in ((Get-ADForest).domains)) { get-aduser -filter * -server $domain -Credential $creds -properties `
 displayname,samaccountname,cn,distinguishedname,whencreated,whenchanged,enabled,passwordlastset, passwordneverexpires,lockedout,cannotchangepassword,passwordnotrequired }
#dump all records to a .csv file
    $AllUsers | Export-Csv .\AllUsers_corp.csv -NoTypeInformation

…but when I view the resulting .csv, some of the columns are labeled

WriteDebugStream

with a value of
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection

Yet, I do get all of my properties.

What is causing the other errors? Is it because I am not an Enterprise Admin?

Thanks

So, to neaten this up a bit:

$creds = Get-Credential

ForEach ($domain in ((Get-ADForest).domains)) {

get-aduser -filter * -server $domain -Credential $creds -properties `

displayname,samaccountname,cn,distinguishedname,whencreated,whenchanged,enabled,passwordlastset, passwordneverexpires,lockedout,cannotchangepassword,passwordnotrequired |

Export-Csv .\AllUsers_corp.csv -NoTypeInformation -Append

}

Because I’m not certain what value you’re getting from saving it all in a variable. I suspect Get-ADUser is indeed having some kind of problem, but I’m not sure why it… like, I’ve not seen it to that before :). I’d add some debugging information.

$creds = Get-Credential

$VerbosePreference="Continue"

ForEach ($domain in ((Get-ADForest).domains)) {

Write-Verbose "Working on $domain"

get-aduser -filter * -server $domain -Credential $creds -properties `

displayname,samaccountname,cn,distinguishedname,whencreated,whenchanged,enabled,passwordlastset, passwordneverexpires,lockedout,cannotchangepassword,passwordnotrequired |

Export-Csv ".\$($domain.name) AllUsers_corp.csv" -NoTypeInformation -Append

}

I’ve added some verbose output, and made a change so each domain goes to a unique CSV. That’ll let you see which domain is causing the problem, if it’s limited to just some domains and not happening to all of them.

All my errors went away like magic, thanks Don. Maybe get-ADUsers didn’t like my $AllUsers variable if I wasn’t an Enterprise Admin (this worked at another company where I was an EA.)

How would I construct a foreach to as export many csv’s as there are domains? The Append is handy for some degree of separation but I would like separate reports at this stage.

It -should- be doing separate CSVs per domain, because I inserted the domain name into the filename. As the domain name changes, it’ll write to a new file. Line 14, although you may need to tweak it a bit syntactically.