PowerShell : Exporting multi-valued attribute via Export-Csv cmdlet

Standard

The attributes that are multi-valued are hard to export to a CSV via the Export-Csv cmdlet as the exported value just shows the string type in Excel/Notepad.

For instance, take a look below when I try to export the proxyAddresses attribute values in PowerShell console and to a CSV later.

image

image

I found out that you can using the join function i.e @{Name=’proxyAddresses’;Expression={[string]::join(“;”, ($_.proxyAddresses))}} can export the multiple values from a multi-valued attribute to a CSV accordingly.

So, this is how it would look for the query I ran above.

Get-QADUser test.user1 -IncludeAllProperties | select name,@{Name='proxyaddresses';Expression={[string]::join(";", ($_.proxyaddresses))}} | Export-Csv .testUser1.csv

To accomplish the export of all values in a spreadsheet/csv.

image

This should come handy also when you are trying to retrieve the ‘memberof’ attribute of users and trying to export all groups that a user is part of to a CSV. Just replace the attribute you are after in the join function above.

Add -notype paramater at the end of the export-csv cmdlet to avoid the #type information in the first row in csv.