Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Need help importing a CSV file using IMPORT-CSV commandlet

$
0
0

Hello:

I am fairly new to Windows Powershell and need some help. I want to import a CSV file using the import-csv commandlet but getting some name errors because of the csv file header not containing quotation marks. I could manually add new header names in using the -header option but I want to script this.

I thought about importing the first line of the CSV file to some sort of array and then doing a replace to add the quotation marks in to each row name. Would get-content achieve this?

An example would be this:

name, address, phone number, school

converted to

"name", "address", "phone number", "school"

I'd want to be able to import the entire CSV file, cut the first row and do the change. Then pipe those results to import-csv commandlet. Any help would be much appreciated.

I am downloading this CSV file from a website that does not put the quotation marks on the header row.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>