Export-Csv with Append

by Aug 29, 2012

Finally, in PowerShell v3 the cmdlet Export-Csv got a new parameter called -Append! Now you can easily append information to an existing CSV file. Have a look:

Get-Process | 
  Export-Csv $env:temp\list.csv -UseCulture -NoTypeInformation -Encoding UTF8

Get-Process | 
  Export-Csv $env:temp\list.csv -UseCulture -NoTypeInformation -Encoding UTF8 -Append

Import-Csv $env:temp\list.csv -UseCulture | 
  Sort-Object -Property ID | 
  Select-Object Name, ID

As you can see, the second line has appended information to the existing CSV file which is why you get back duplicate process IDs when you read in the file.

Note that you can of course only add new data to an existing CSV file that is of the same type. You cannot mix, for example, processes and services because a CSV file can only have one set of headers.

Twitter This Tip! ReTweet this Tip!