PowerShell Genie

Export-Csv output looks wrong

Incident 2 min read Troubleshooting walkthrough

Documentation: Microsoft Learn

Work the problem

The CSV contains internal names

Fictional case: A report uses Get-Service | Format-Table Name,Status | Export-Csv. The resulting headers include formatting metadata.

Which repair preserves the intended columns?

Reasoning notebook

Record the evidence that supports your answer and the check you would run next. Your notes stay in this browser — nothing is uploaded.

Why it happens

Format-Table and its siblings replace real objects with formatting instruction objects, and Export-Csv faithfully serializes those instructions rather than the data. Out-String has a comparable effect by collapsing everything into one string. It looked right in the console because the console is where formatting was meant to be the last step.

Check this first

1PS> Get-Service | Select-Object Name,Status | Export-Csv .\services.csv -NoTypeInformation

What to look for

Select-Object creates data objects with those properties. Format-Table creates display instructions that should not be exported as records.

Object flow

Where did the CSV become garbage?

Get-Serviceservice objects
→
Format-Tableformatting records
→
Export-Csvserializes wrong object type

Genie: find the stage where data objects stop being data objects.

Bad

Get-Service | Format-Table Name,Status | Export-Csv services.csv

Good

Get-Service | Select-Object Name,Status | Export-Csv services.csv -NoTypeInformation

Working through it

  1. Remove any Format-Table, Format-List, or Out-String sitting between the data and Export-Csv.
  2. Choose columns with Select-Object instead, since that emits objects rather than formatting directives.
  3. Add -NoTypeInformation on Windows PowerShell to drop the type comment from the first line.
  4. Pipe into Get-Member when unsure and check that the type name is not one of the Format types.
  5. Flatten any array-valued property through a calculated property that joins it, or the column receives a type name.

Avoiding it next time

Verify the repair: Import the new CSV and confirm Name and Status are the properties, then compare the row count with the intended service set.

Primary documentation

Export-Csv reference · Get-Service reference

Work through the incident

Repair a service CSV

A service export contains formatting metadata instead of the columns you need.

Review the lesson

Genie guideExport-Csv output looks wrong

Start with the symptom, then inspect the checks and evidence. These are investigation steps; more than one cause may fit.