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
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
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.
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!!
Link | August 15th, 2011 at 3:03 pm
Hi Steve, Before the first ‘pipe’, try this instead.
select displayname,@{Name=’proxyaddresses’;Expression={[string]::join(“;”, ($_.proxyaddresses))}}
Link | August 15th, 2011 at 11:28 pm
Hi Shariq,
Thank you for this very valuable tip. Brilliant.
Link | January 5th, 2012 at 9:43 am