Tag Archives: PowerShell

PowerShell Import-Csv Error

I ran across the following error while working with a PowerShell script I was developing:

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.

It had me stumped for a while. The Impor-Csv command was failing, but the file name was good (I could cat the files contents to standard out).

Long story short, the error came from having trailing blank columns in my CSV. Import-Csv uses the first row in the CSV as names for the columns (unless you specify otherwise) and when you have blank columns (or at least multiple blank columns) it causes this error as it doesn’t have a valid name for them. The underlying culprit for the error was actually Microsoft Excel. I was exporting a spreadsheet to a CSV and the spreadsheet had previously had some trailing columns. I values to the columns, but apparently Excel decided they should still show up in the export. Fully deleting the columns so they didn’t show up in the CSV resolved the problem.