I have CSV file
MyFile.csv. It contains following data:
Now I am fetching few records from SQL Server as follows:
I am not able to find a way to append these new records to existing CSV file. I don't want to repeat header again. I don't have MS Excel, just want to play with CSV. I tried using
Add-content, but it didn't worked out.
Best How To :
Since PowerShell v3 the
Export-Csv cmdlet has an
-Append parameter that allows appending to an existing CSV.
$data | Export-Csv 'MyFile.csv' -Append -NoType
On earlier versions you can work around that by converting the data to CSV, skip the header line, then append to the output file using
$data | ConvertTo-Csv -NoType | select -Skip 1 | Add-Content 'MyFile.csv'