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.
0 Comments
[ + ] Show comments
Answers (2)
Answer Summary:
Please log in to answer
Posted by:
tpr
3 years ago
Posted by:
Nioky
3 years ago
Top Answer
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.
Comments:
-
Thanks. I'll give those suggestions a shot. - tpr 3 years ago