## Powershell Export-csv question

I have a script that sets an OU base, then searches within it for groups with a single member. Get-ADGroup -SearchBase $oupath -Filter * -Properties * | where {$_.members.count -eq 1} | select DistinguishedName,Members When I run it without export-csv so that the results are displayed, I get the group name and the single member as expected. When I add the |export-csv "path\to\file.csv" -NoTypeInformation, the group name shows up properly in the Distinguished Name column, but I get this in the Members column: Microsoft.ActiveDirectory.Management.ADPropertyValueCollection Do I need to add an option to the export-csv command, or is there some other issue with the command itself? Thanks.

Posted by: tpr 9 months ago
0
Sorry, not sure why I didn't have any formatting options for the question. I tried to at least put the script line in its own line.
Posted by: Nioky 9 months ago
0

Hi,

Even if there is only one member, this field is declared as multivalued (array).

Here is how I think I'll do it if it was me :

Get-ADGroup -SearchBase $oupath -Filter * -Properties DistinguishedName,Members | where {$_.members.count -eq 1} | select DistinguishedName,@{N='Members';E={$_.Members[0]}} | Export-Csv "C:\Users\$(\$env:USERNAME)\Desktop\test.csv" -NoTypeInformation -Delimiter ";"

If there was more than one members, I think there will be no choice but creating a loop to process each value of the array.

• Thanks. I'll give those suggestions a shot. - tpr 9 months ago

#### Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

question