Author Posts

January 7, 2018 at 5:57 pm

I'm having a problem with getting right columns using Import-Csv -Header
My CSV file is


PS code that I'm using is

$headers = "BBB", "CCC"
$files = Import-Csv "C:\Users\karol\Desktop\CSV_TEST\Files.csv" -Header $headers

The result are not what it would looks like.

— —
aaa1 bbb1
aaa2 bbb2

Any idea what is the issue? THX

January 7, 2018 at 6:38 pm

Specifies an alternate column header row for the imported file. The column header determines the names of the properties of the object that Import-Csv creates.

Enter a comma-separated list of the column headers. Enclose each item in quotation marks (single or double). Do not enclose the header string in quotation marks. If you enter fewer column headers than there are columns, the remaining columns will have no header. If you enter more headers than there are columns, the extra headers are ignored.

When using the Header parameter, delete the original header row from the CSV file. Otherwise, Import-Csv creates an extra object from the items in the header row.

January 7, 2018 at 6:41 pm

Seems like your original CSV file already has headers ... at least AAA and BBB. Either you use the existing headers in CSV file or you specify them with your cmdlet. If I'm not wrong you cannot combine them.