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.
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.
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.
So, I’ve just run a report that used this expression, but is there a way to have it generate the display names, rather than the DN?
Thanks Rick!!
Hi Steve, Before the first ‘pipe’, try this instead.
select displayname,@{Name=’proxyaddresses’;Expression={[string]::join(“;”, ($_.proxyaddresses))}}
Hi Shariq,
Thank you for this very valuable tip. Brilliant.