Change only the header row of a large csv

I have a large CSV file with a couple of dozen columns, thousands of row. It’s auto-updated daily by one system and another system will auto-import the CSV but the second system expects the headers to be different from what the first system generates. Alas I have no control over either system so the solution is to change the header row of that CSV using PowerShell.

Given a list of matches, e.g.

{“Green Fruit” -> “Apples”,
“Large Vehicle” -> “Van”,
“President” -> “Head Honcho”}

What’s the quickest/easiest way to parse the CSV and end up with correct headers?

Using -Header parameter creates an alternate column header row on top of the original header row. I used -Skip parameter to skip the first row (which now contains your original header list). Now you can export the csv with new headers.

Import-Csv -Path .\importedfile.csv -Header NewFruit,NewVehicle,NewPresident |
Select-Object -Skip 1 | Export-Csv -NoTypeInformation -Path .\newfile.csv

That did the trick, spiffy automated correction is now running.

Thanks for your help!

Graham