Expanding Objects in Export-CSV

Welcome Forums General PowerShell Q&A Expanding Objects in Export-CSV

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 11 months ago.

  • Author
  • #43566

    Topics: 9
    Replies: 11
    Points: 0
    Rank: Member

    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

    Topics: 3
    Replies: 263
    Points: 73
    Helping Hand
    Rank: Member

    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

    Topics: 9
    Replies: 11
    Points: 0
    Rank: Member

    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.

The topic ‘Expanding Objects in Export-CSV’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort