Home » excel » format excel file after export-csv powershell

format excel file after export-csv powershell

Posted by: admin May 14, 2020 Leave a comment


Brand new to powershell and trying to modify an existing script.

There is a line that exports a csv file.

Get-Devices $accountID | Export-Csv -Path $DevicesCSV -NoTypeInformation -NoClobber

and It does what it is supposed to do and I get a file in the path specified…

What I want to do is make the file look pretty, make it into a table in excel so columns can be sorted. Add formatting, etc.
I do not see any options to do that and need some guidance on how to accomplish this.

How to&Answers:

There are some workarounds, but the easiest way would be to use dedicated module for this, such as ImportExcel by dfinke. It allows you to work with Excel files both ways (importing/exporting).

Get-Help is your friend if you want to learn more about what specific cmdlets like Export-Excel could do.

If you want to sort the data, you can do this before exporting, using Sort-Object cmdlet.