Expanding Objects in Export-CSV

This topic contains 2 replies, has 2 voices, and was last updated by  Greg Tate 1 year, 11 months ago.

  • Author
  • #43566

    Greg Tate

    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!

  • #43578

    random commandline

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

    # Example
    $nums = 'one','two','three'
        'one' = 'one'
        'nums' = $nums -join ','
    }  | Export-Csv .\test.csv
  • #43602

    Greg Tate

    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 1 year, 11 months ago by  Greg Tate. Reason: formatting

You must be logged in to reply to this topic.