/build/static/layout/Breadcrumb_cap_w.png

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:
Posted by: tpr 1 month ago
2nd Degree Black Belt
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 1 month ago
Yellow Belt
0

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 2 weeks ago

Don't be a Stranger!

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

Sign up! or login

View more:

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ