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.
Ahh! Thank you! thank you! thank you!!!
Thanks. That pointed me in the right direction
Great!
Thanks! I had an extra tab at the end of each line in my file.
Thank you very much for explaining a very unhelpful error message.
This solved my problem, thanks!
he,
you have to do this!
this resolve all problem.
$csv1 = “C:…….csv”
cat $csv1 | % {$_.replace(“,,”,”")} | out-file c:\………csv
I added the -header command and it resolved this once I knew what the culprit was, so:
import-csv “filename.csv” -Header (“Col1″,”Col2″,…)
This resolves the problem above without editing the file. Thanks for pointing me in the right direction.
many thanks , this helped me a lot
Many thanks! That helped me a lot!
Just want to say that over two years since the original post your entry here is still bailing people out (that would be me!)
10K thanks for your help.
Thanks so much for posting. Save me so much time!
Buen posting
Thank you for this!
Thanks!