Export PowerShell Output to CSV

How to export PowerShell output to CSV with Export-Csv, how it differs from Out-File, and what to check for encoding, delimiters and sharing.

Turning PowerShell output into a CSV file looks simple, but the cmdlet you choose decides whether you get structured, re-importable data or a text snapshot of what the console showed. This review covers what each approach produces, where each one fits, and what to check before you share the file. It describes documented cmdlet behavior. No test results were supplied for this article, so confirm the details against the PowerShell version you run.

Short recommendation

Use Export-Csv, or ConvertTo-Csv if you need the CSV text in the pipeline, when the output will be opened in a spreadsheet, imported into another tool, or read back with Import-Csv. The main benefit is that each object becomes one row and each selected property becomes one column, with delimiters and quoting handled for you. The main tradeoff is that CSV is flat. Nested objects, arrays and properties that appear only on some objects do not come through intact unless you reshape the data first.

Plain text from Out-File is the better choice when a person only needs to read the result, for example in a log, a quick report or a ticket attachment, and nobody will parse it. Out-File keeps the console's table or list layout. It does not produce CSV.

What the conversion actually changes

PowerShell commands emit objects, not text. Export-Csv reads the properties of each object and writes them as delimited text. By default it uses a comma, quotes fields as needed, and writes a header row of property names. The values are converted to strings. The structure of the data changes, but nothing changes visually. When you import the file again with Import-Csv, you get objects back, but every value is a string. Numbers, dates and booleans lose their original types.

Out-File works differently. It sends objects through the same formatting system the console uses and writes the rendered text. What lands in the file is padded columns, header underlines and possibly truncated values, depending on the line width set by the -Width parameter or the host. A file named .csv that was written with Out-File is still formatted text, not comma-separated data.

Out-File vs Export-Csv at a glance

Aspect | Out-File | Export-Csv
Input it expects | Anything; renders it as console-style text | Objects with properties
Output format | Formatted text (table or list layout) | Delimited text with a header row
Wide values | May be truncated to the line width | Written in full
Re-import with Import-Csv | Not meaningful | Yes, values return as strings
Good for | Human-readable logs and reports | Spreadsheets, data exchange, scripting

Basic patterns

Select the columns you want before exporting. This keeps the file readable and avoids dozens of unneeded properties.

Get-Process |
    Select-Object Name, Id, CPU |
    Export-Csv -Path .\processes.csv -NoTypeInformation

If you want CSV text but need to control how it is written, for example to append to an existing file or send it somewhere other than a file, convert it first and then write it.

Get-Service |
    Select-Object Name, Status |
    ConvertTo-Csv -NoTypeInformation |
    Out-File -FilePath .\services.csv -Encoding utf8

This is the one case where Out-File and CSV belong together. Out-File writes lines of text that ConvertTo-Csv has already formatted as CSV.

For tab-separated output, set the delimiter to a tab character using PowerShell's backtick escape:

Get-ChildItem -File |
    Select-Object Name, Length, LastWriteTime |
    Export-Csv -Path .\files.tsv -Delimiter "`t" -NoTypeInformation

The -UseCulture switch uses the list separator from the current culture settings. This can help where the spreadsheet software expects a semicolon, but it also makes the file's format depend on the machine that created it.

Common mistakes that corrupt the result

  • Piping Format-Table or Format-List into Export-Csv: the format cmdlets emit formatting instructions, not your data, so the CSV fills with internal formatting properties. Use Select-Object instead.
  • Exporting plain strings: a string's only property is Length, so piping text lines into Export-Csv produces a column of numbers rather than the text.
  • Inconsistent objects: the columns come from the first object. Properties that appear only on later objects are dropped. Select the full set of properties explicitly when the objects vary.
  • Nested values: arrays and complex objects are written as their type name, for example System.Object[], instead of their contents. Flatten them first, for instance with a calculated property that joins array items into one string.
  • Appending to a different shape: -Append expects the new objects to match the existing columns. Mismatches raise an error, or are forced through with -Force, which can leave misaligned data.

Version differences worth knowing

Windows PowerShell 5.1 adds a #TYPE line at the top of the file unless you pass -NoTypeInformation. PowerShell 6 and later leave it out by default and offer -IncludeTypeInformation if you want it. In those versions, -NoTypeInformation is still accepted for compatibility. Including it keeps a script working the same way in both.

PowerShell 7 also adds -UseQuotes and -QuoteFields to control which fields are quoted. Earlier versions quote every field. If another system is strict about quoting, check which version produced the file.

Default text encoding also differs between Windows PowerShell 5.1 and PowerShell 7, and between Out-File and Export-Csv in the older version. PowerShell 7 defaults to UTF-8 without a byte order mark. Rather than relying on defaults, pass -Encoding explicitly whenever the file may contain characters outside basic ASCII.

Will the file stay usable after sharing?

CSV is plain text, so copying, emailing or committing it to version control keeps it intact as long as the encoding and delimiter are understood at the other end. Most problems come from the receiving program, not from PowerShell.

  • Encoding: some spreadsheet applications guess the encoding when opening a CSV and may misread accented or non-Latin characters in a UTF-8 file without a byte order mark. In PowerShell 7, -Encoding utf8BOM is a common workaround. Whether a given application needs it was not tested for this article.
  • Delimiter: a comma-separated file can open as a single column where the regional list separator is a semicolon, and the reverse. Agree on the delimiter with whoever receives the file.
  • Data types: spreadsheets may reinterpret values on open, for example dropping leading zeros or converting text that looks like a date. That happens in the destination, not in the CSV, and is a reason to keep the original file unedited.
  • Line endings and very long fields are rarely a problem for standard CSV readers, but tools with strict parsers should be checked with a sample file first.

Because the content stays ordinary text, assistive technology and search behave the same as with any other text or spreadsheet file. No accessibility testing of specific readers or spreadsheet programs was available for this article. When the audience only needs to read a summary, a short plain-text or formatted report written with Out-File may be easier to follow than a raw data file.

Choosing between them

If the output feeds a spreadsheet, a database import or another script, export objects with Export-Csv, select the columns explicitly, flatten nested values, and set the encoding. If the output is a record for people to read, Out-File is simpler and keeps the familiar console layout. Only reach for Out-File together with CSV when you have already converted the objects with ConvertTo-Csv.

Gaps in this review

This article relies on documented cmdlet behavior and general CSV conventions. No measurements, compatibility tests or version-specific test outputs were supplied. Check encoding defaults, quoting options and how particular spreadsheet or import tools behave in your own environment before relying on them.