Fix unexpected Length output in Export-Csv

Why PowerShell's Export-Csv writes a Length column instead of your text, how to confirm the cause, and how to fix it or fall back to plain text.

If Export-Csv gives you a file with one column called Length, filled with numbers instead of your text, the cmdlet is not broken. It is doing what it was built to do. Export-Csv converts objects into rows and columns. It does not write lines of text. The fix depends on what you sent into it, and sometimes the right fix is not to use CSV.

Is Export-Csv the right tool for this job?

Use Export-Csv when each item is an object with named properties that you want as columns.
The main benefit is a structured, consistently quoted file that spreadsheet tools, databases and other scripts can parse.
The decisive tradeoff is that Export-Csv writes properties, not raw values. Plain strings, unconverted hashtables and formatted output come out as metadata columns instead of your data.
If you only need one value per line, plain text is the better choice. Write it with Set-Content or Out-File. A single-column CSV only helps when the destination specifically expects a header row and CSV quoting.

What Export-Csv actually changes

For each object it receives, Export-Csv reads the object's properties. It takes the property names from the first object as the header row. It then writes each object's values as delimited, quoted fields.
This is a structural change: objects become rows and columns. The characters in the values are written as they are, subject only to the chosen file encoding. Nothing is reversed, mirrored or swapped for styled Unicode lookalikes.
This explains the Length column. A .NET string exposes one public property, Length, so a string sent into Export-Csv becomes a row containing only its length.

'apple','banana' | Export-Csv -Path fruit.csv -NoTypeInformation

# fruit.csv contains:
"Length"
"5"
"6"

The output matches the mechanism: "apple" has five characters and "banana" has six.
Length counts UTF-16 code units, not the characters you see. An emoji outside the Basic Multilingual Plane counts as 2. So does a letter written as a base character plus a combining accent. Emoji built from several code points count higher still.
If the numbers look larger than the characters you can count, that is another sign you are looking at string metadata, not your data.

Windows PowerShell 5.1 adds a first line such as #TYPE System.String unless you pass -NoTypeInformation. PowerShell 6 and later leave that line out by default.

Why the unexpected columns appear and how to tell the causes apart

Symptom | Likely cause | Distinguishing check
A single Length column | Strings were sent in, for example from Get-Content, a string array, or Select-Object -ExpandProperty | $data | Get-Member reports TypeName: System.String
Columns such as Length, LongLength, Rank and Count | A whole array was passed to -InputObject instead of being piped | Get-Member -InputObject $data reports System.Object[]
Columns such as IsReadOnly, IsFixedSize, Keys, Values and Count | A hashtable was exported without being converted to an object | $data | Get-Member reports System.Collections.Hashtable
Columns named like ClassId2e4f51ef... | Format-Table or Format-List output was piped to Export-Csv | A Format-* cmdlet appears earlier in the pipeline
Some expected columns are missing for later rows | The header was built from the first object's properties only | Compare property sets with Get-Member on several items

Run one check before exporting: pipe the data to Get-Member, or inspect $data[0].GetType().FullName. That separates the causes above.
The behaviors in the table are standard PowerShell object handling. However, no pipeline or sample file was supplied for this article. Treat the table as a map of likely causes, and confirm which one applies with that check rather than assuming.

Targeted fixes

For strings, wrap each value in an object with a named property, so Export-Csv has a real column to write.

'apple','banana' |
    ForEach-Object { [pscustomobject]@{ Fruit = $_ } } |
    Export-Csv -Path fruit.csv -NoTypeInformation

# fruit.csv contains:
"Fruit"
"apple"
"banana"

A calculated property does the same thing inside Select-Object:

'apple','banana' |
    Select-Object @{ Name = 'Fruit'; Expression = { $_ } } |
    Export-Csv -Path fruit.csv -NoTypeInformation

A common source of the problem is -ExpandProperty. It turns each object into a bare value, which for text means a string. Leave it off when you are exporting to CSV.

# Produces a Length column
Get-Process | Select-Object -ExpandProperty Name | Export-Csv names.csv -NoTypeInformation

# Keeps a Name column
Get-Process | Select-Object Name | Export-Csv names.csv -NoTypeInformation
  • Arrays: pipe the collection into Export-Csv instead of passing it to -InputObject. Piping exports each element separately.
  • Hashtables: cast to [pscustomobject] before exporting. Recent PowerShell 7 releases document direct handling of dictionaries. Check the help for your installed version before relying on it.
  • Formatted output: remove Format-Table or Format-List from the pipeline. Use Select-Object to choose columns.
  • Mixed objects: give every object the same column set with an explicit Select-Object property list, so later rows are not cut down to the first object's columns.
# Array: pipe it
$list | Export-Csv -Path out.csv -NoTypeInformation

# Hashtable: convert it
[pscustomobject]$hash | Export-Csv -Path out.csv -NoTypeInformation

# Mixed objects: fix the column set
$items | Select-Object Name, Size, Owner | Export-Csv -Path out.csv -NoTypeInformation

If you never needed columns, the plain-text fallback is simpler. It writes one value per line with no header and no quotes:

'apple','banana' | Set-Content -Path fruit.txt

Will the file stay readable after copying or sharing?

A CSV file is plain text, so the characters carry over unchanged when copied. Whether the rows and columns survive depends on how the receiving program parses the file.
Three settings matter most:
Delimiter. Use -Delimiter "`t" for tab-separated output, or -UseCulture to use the system list separator.
Encoding. The default encoding differs between Windows PowerShell 5.1 and PowerShell 7, so set -Encoding explicitly when the file will be opened elsewhere. Whether a particular spreadsheet application reads UTF-8 correctly with or without a byte order mark is something to confirm with that application. It should not be assumed from one successful opening.
Quoting. Export-Csv quotes every field by default. PowerShell 7 adds -UseQuotes and -QuoteFields if the destination dislikes the quotes.

No characters are swapped for lookalike symbols, so search, editing and screen readers all encounter the real text.
Raw CSV is still awkward to read directly, because the commas and quotation marks are read out or displayed along with the values. For people who will read the content rather than import it, a plain list or a table rendered in the destination app is easier to follow.
No specific assistive technology or destination app was tested for this article.

Pasting CSV into a chat or email body usually shows the raw comma-separated text, not a table. Tab-separated text is more often split into cells when pasted into a spreadsheet grid. Check that in the app you actually use before relying on it.

What this review could not confirm

  • No reader pipeline, input sample or output file was supplied, so the cause of any particular Length column has to be confirmed with Get-Member.
  • Version-specific defaults, including encoding, type-information headers and dictionary handling, should be checked with Get-Help Export-Csv -Full on the PowerShell version you run.
  • No destination applications or assistive technologies were tested, and no measurements were taken.