Import CSV Files in PowerShell: What Import-Csv Changes and When to Use It

A practical review of PowerShell's Import-Csv: how it turns CSV and TSV text into objects, how it handles headers, delimiters and encoding, and when plain text is the better choice.

Import-Csv is the built-in PowerShell cmdlet for reading comma-separated and other delimited text files. It turns each row into an object you can filter, sort and pass along the pipeline. This review covers what the conversion keeps and what it changes, so you can judge whether it fits your task or whether reading the file as plain text would serve you better.

Is Import-Csv suitable for your task?

Import-Csv is a good fit when the file has a consistent header row and a consistent delimiter, and you want to work with columns by name. Its main benefit is that it parses for you: quoted fields, delimiters inside quotes and line breaks inside quoted fields are handled without hand-written splitting logic, and every row comes out as an object with named properties.

The main tradeoff is that every value arrives as a string. Numbers, dates and booleans are not detected or converted. That avoids silent changes, so leading zeros in ZIP codes or account IDs survive, but it also means any sorting, math or date comparison needs an explicit conversion.

Plain text is the better choice when the file is not truly tabular. Examples include log files with a few comma-separated parts, files with multiple header sections or comment lines, files where row lengths vary on purpose, or cases where you need the exact original bytes and line endings. In those cases, Get-Content or a raw read with your own parsing gives you more control.

What the transformation actually changes

Import-Csv does not modify the file on disk. It reads delimited text and produces in-memory objects, one per data row. The column names come from the first line, unless you supply your own with the -Header parameter. Each column becomes a property, and each cell becomes that property's string value.

# people.csv
Name,Zip,Joined
"Rivera, Sam",02134,2024-03-01
Lee,90210,2023-11-15

PS> $rows = Import-Csv -Path .\people.csv
PS> $rows[0].Name
Rivera, Sam
PS> $rows[0].Zip
02134
PS> $rows[0].Zip.GetType().Name
String

The example illustrates documented behavior rather than results from a recorded test. The quoted field keeps its embedded comma and loses its surrounding quotes. The ZIP code keeps its leading zero because it stays a string. The date is text, not a DateTime value.

Keep two things separate: the stored data and how it looks in the console. The table you see after running Import-Csv is PowerShell's default formatting of the objects. It may truncate or hide columns to fit the window. That display does not change the objects, and Format-Table output is meant for viewing, not for saving or further processing.

Key parameters

Parameter | What it does | When to use it
-Path / -LiteralPath | Specifies the file to read; -LiteralPath treats wildcard characters literally | Use -LiteralPath for file names containing brackets or similar characters
-Delimiter | Sets the field separator character | Tab-separated, semicolon-separated or pipe-separated files
-UseCulture | Uses the list separator from the current culture settings | Files produced by regional software that follows the system separator
-Header | Supplies column names instead of reading them from the first line | Files with no header row
-Encoding | Sets the text encoding used to read the file | Non-ASCII text, or files from other systems or older tools

Reading TSV and other delimited files

For tab-separated files, pass a tab character as the delimiter. In PowerShell, a backtick followed by t inside double quotes produces a tab. For delimited text that is already in a string, such as clipboard contents or output from another command, ConvertFrom-Csv applies the same parsing without needing a file.

Import-Csv -Path .\data.tsv -Delimiter "`t"
Import-Csv -Path .\export.csv -Delimiter ';'
Get-Clipboard | ConvertFrom-Csv

Header pitfalls

  • If a file has a header row and you also pass -Header, the original header line is imported as an ordinary data row. Skip or filter it out.
  • If you supply fewer header names than there are columns, the extra columns are dropped. If you supply more, the extra properties exist but have no data.
  • Duplicate column names in the header row cause Import-Csv to fail. Rename the columns in the file, or read it with -Header and your own unique names.
  • Header names that contain spaces or punctuation are still valid property names, but you must quote them when you reference them, for example $row.'Order ID'.

Encoding and character fidelity

Characters are preserved only if the file is decoded with the right encoding. The default differs between Windows PowerShell 5.1 and PowerShell 7 and later. PowerShell 7 and later default to UTF-8 without a byte order mark. A file that contains accented letters, non-Latin scripts or emoji can come in garbled if the assumed encoding is wrong. If you know how the file was produced, specify -Encoding explicitly instead of relying on the default. Check the actual default for your version in its documentation rather than assuming it.

Converting values to usable types

Because everything is a string, sorting a numeric column without conversion sorts it as text, so 10 comes before 9. Convert values at the point of use, or build typed objects once with calculated properties. Be aware that converting to a number removes leading zeros. Keep identifier-style columns as strings.

Import-Csv .\orders.csv |
    Sort-Object { [int]$_.Quantity } -Descending

Import-Csv .\orders.csv | Select-Object OrderId,
    @{ Name = 'Quantity'; Expression = { [int]$_.Quantity } },
    @{ Name = 'Date';     Expression = { [datetime]$_.Date } }

Date conversion depends on the date format in the file and can depend on culture settings. Test it against your actual data rather than assuming a given format will parse.

Will the data stay usable after exporting or sharing?

To produce a file again, use Export-Csv or ConvertTo-Csv on the objects, not on formatted console output. Piping Format-Table output into Export-Csv writes formatting records instead of your data.

  • Windows PowerShell 5.1 adds a #TYPE line at the top of exported files unless you use -NoTypeInformation. PowerShell 6 and later omit it by default. Other tools may treat that line as data.
  • The exported text may not match the original byte for byte. Quoting style, column order, encoding and line endings can differ, even when the values are the same.
  • If you converted values to numbers or dates, the export writes their string form in the current format. That form may differ from the original text, for example a reformatted date or a number without its leading zeros.
  • Spreadsheet applications may reinterpret values when they open a CSV file, for example by dropping leading zeros or reformatting dates. That happens in the spreadsheet application, not in PowerShell.

Copying the console table and pasting it elsewhere gives you aligned display text, not CSV. It may be truncated to the window width. If someone needs the data, share the exported file or the output of ConvertTo-Csv instead. If a screen reader user needs to review results, a CSV file opened in an accessible spreadsheet or editor is usually easier to navigate than space-aligned console output. That suggestion is a general principle, not a tested result for any specific assistive technology.

Large files

Import-Csv emits objects one at a time down the pipeline. Filtering it directly with Where-Object, or processing it with ForEach-Object, avoids holding the whole file in memory. Assigning the result to a variable loads every row at once. No performance measurements were supplied for this review, so test with your own file sizes before relying on either approach for large data.

Evidence gaps

This review is based on documented cmdlet behavior and general principles. No benchmarks, version-specific test runs or checks against specific destination applications were provided. Confirm encoding defaults, edge-case handling of malformed rows and the behavior of whatever application will open your exported files in your own environment.