Replacing CSV File Headers

by Sep 2, 2016

PowerShell 2+

When you read in CSV data and would like to rename the CSV headers, here is a simple approach: just read in the text line by line, and skip the first line (which holds the CSV headers). Then, replace the headers with a list of your own header names:

$header = NewHeader1’, 'NewHeader2', 'NewHeader3'

Get-Content N:\somepathtofile\userlist.csv -Encoding Default | 
 Select-Object -Skip 1 |
 ConvertFrom-CSV -UseCulture -Header $header

Twitter This Tip! ReTweet this Tip!