PowerShell: How to Use Export-Csv with No Quotes


Often you may want to use the Export-Csv cmdlet in PowerShell to export data to a CSV file with no quotes.

Fortunately this is easy to do by using the convertto-csv cmdlet instead and by using the -replace operator to replace all quotes with nothing:

$data | convertto-csv -NoTypeInformation | % {$_ -replace '"',''} | out-file 'new_data.csv'

This particular example will export the data saved in the variable named $data to a CSV file named new_data.csv with no quotes.

The following example shows how to use this syntax in practice.

Example: How to Use export-csv with No Quotes in PowerShell

Suppose we have a CSV file saved in the following location:

  • c:\users\bobbi\basketball_data.csv

Here is what this file looks like when we open it in Notepad:

Suppose that we would like to import this file into PowerShell, then simply export it with no quotes.

Suppose we attempt to use the following syntax to do so:

$data = Import-Csv -Path c:\users\bobbi\basketball_data.csv
$data | convertto-csv -NoTypeInformation | out-file 'new_data.csv' 

The following screenshot shows how to use this syntax in practice:

We can then navigate to this CSV file that we exported named new_data.csv and view it:

Notice that the data has been successfully exported but it contains quotes around the values by default.

We can use the following syntax to do so:

$data = Import-Csv -Path c:\users\bobbi\basketball_data.csv
$data | convertto-csv -NoTypeInformation | % {$_ -replace '"',''} | out-file 'new_data.csv' 

The following screenshot shows how to use this syntax in practice:

PowerShell export-csv with no quotes

We can then navigate to this CSV file that we exported named new_data.csv and view it:

Notice that this file contains all of the same data as basketball_data.csv but without any quotes around the data.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to List Files in Directory by Date
PowerShell: How to Get Most Recently Modified File in Directory
PowerShell: How to List All Files in Directory to Text File
PowerShell: How to Delete All Files with Specific Extension

Leave a Reply