PowerShell Coding Samples by Patrik
Import CSV Without First Line in PowerShell
Given a CSV file with some comments on the first line and starting with the headers on the second line. The
Import-Csv cmdlet will not work in this scenario. In this case, you need to skip the first line to recognize the headers.
You need to get the file and then use the
Select-Object cmdlet with the Skip parameter to skip the first line and then convert this to CSV.
In this sample, we then use the
ConvertFrom-Csv cmdlet to convert into CSV format.
$csvFile = 'file.csv' $csvData = Get-Content -Path $csvFile | Select-Object -Skip 1 | ConvertFrom-Csv
Leave a Comment
All fields are required. Your email address will not be published.