Link to home
Create AccountLog in
Avatar of bndit
bndit

asked on

Powershell: Best way to work with header column names in a CSV file

I have to work with a CSV file that has no header column names. I know what these column names are; so what would be the best approach to work with a file like this?

Is this the best way to handle it?

$header = "FirstName","LastName","EmployeeNumber" # so forth and so on

Import-csv c:\temp\myfile.csv -header $header

Open in new window


I'm pretty sure that if a column was deleted and/or added to the file without updating the header array, the import would fail, correct?
SOLUTION
Avatar of Aard Vark
Aard Vark
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of bndit
bndit

ASKER

Agreed; best way will be to have column names to start with.