Posts Tagged export-csv

Powershell error converting text file to csv: the value of argument “name” is invalid

Powershell throws this error when we try to convert a text file (without  header) to csv. We should add headers (column names) to the command to run it properly.

The detailed error message is: Import-Csv : Cannot process argument because the value of argument “name” is invalid. Change the value of the “name” argument and run the operation again.

FIX

———-

If our text file structure is:

User1|NYC|25

User2|WDC|23

User3|NYC|22

Use the below script to convert from txt to csv

Import-CSV -path “c:\folder\sample_text_file.txt” -delimiter “|”  -header (“Name”, “City”, “Age”) | Export-CSV -path “c:\folder\Converted_csv_file.csv”

,

Leave a comment