Skip to content

Not all columns present in CSV output #167

Answered by bk-cs
cjlane0289 asked this question in Q&A
Discussion options

You must be logged in to vote

Based on what you're describing, I believe this behavior is caused by how PowerShell deals with exporting objects to CSV. The first object that's used to create the CSV contains all the columns that will be used in the CSV, and if a new column appears, it's automatically dropped.

You can recreate this with a simple example:

PS>[PSCustomObject] @{col1='abc';col2='def'}, [PSCustomObject] @{col1='ghi';col3='jkl'} | Export-Csv ./test.csv; cat ./test.csv
"col1","col2"
"abc","def"
"ghi",

The easiest way to stop this behavior is to force PowerShell to export your desired properties before the export:

PS> [PSCustomObject] @{col1='abc';col2='def'}, [PSCustomObject] @{col1='ghi';col3='jkl'} | Sele…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by bk-cs
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #166 on January 20, 2022 15:44.