Author Posts

June 16, 2016 at 1:04 pm

When I export to csv and open in Excel, certain columns indicate an array of objects, such as System.String[].
But when I pipe to format-list these fields show their normal values as expected.

What tricks can I use to get my columns to display properly?

As an example, I am using the get-messagetracking cmdlet and doing a simple pipe to export-csv.

Thanks in advance!

June 16, 2016 at 1:30 pm

Use the join operator on the property. (-join ',' or -join "`n")

# Example
$nums = 'one','two','three'
[PSCustomObject]@{
    'one' = 'one'
    'nums' = $nums -join ','
}  | Export-Csv .\test.csv

June 16, 2016 at 2:25 pm

Thanks for the tip!
This help me get to the info I needed.

The end result of my command looks something like:

get-messagetrackinglog -start 6/1/16 -sender sender@company.com | 
select *, 
@{ n='recipients2'; e={$_.recipients -join ','}},
@{ n='recipientstatus2'; e={$_.recipientstatus -join ','}},
@{ n='eventdata2'; e={$_.eventdata -join ','}} |
export-csv -NoTypeInformation -Path export.csv -delimiter ';'

There were three fields returning arrays of strings, so I created new fields for them using the join operator.

  • This reply was modified 2 years, 2 months ago by  Greg Tate. Reason: formatting