October 29, 2013

How to export/pipe/copy results to Excel

Sometimes you just want to paste the result of a cmdlet into an Excel spreadsheet.

First you will probably try to copy the content from a Gridview :

get-process | out-gridview

But you will realise that the column’s headers are missing.

Why not try to pipe the result into the clip command and paste it in Excel :

get-process | clip

Well not so great, everything is in one big column (no delimiter).

Ok, let’s try to convertto-csv before doing the copy :

get-process | convertto-csv -Delimiter "`t" -NoTypeInformation | clip

Looks great … but if you happen to have any french characters, they will not appear in Excel.

So, my final solution is to re-encode the output in UTF8 by saving it to a file :

get-process | export-csv -Delimiter ";" -NoTypeInformation -force -path "$env:TEMP\export-csv.csv" -Encoding UTF8; start-process excel "$env:TEMP\export-csv.csv"


@Adansbrow said...


techat19 said...

Thanks! this save me a few hours of reading and trial and error.

Post a Comment