Export PowerShell to Excel

Forget about exporting data to CSV. 🥱 If you are using PowerShell a lot and want to filter, freezing top rows, adding formulas, and so on – this is what you need! 😎

The module is called ImportExcel and is available at Github and the PowerShell Gallery.

It is super easy to install and use. Here is how to do it!

1. Set the execution policy to require that downloaded scripts are signed by a trusted publisher:

Set-ExecutionPolicy RemoteSigned -Force

2. Install the ImportExcel module from the repository:

Install-Module ImportExcel

3. Run a test command:

Get-Service | Export-Excel "$env:USERPROFILE\Desktop\services.xlsx" -FreezeTopRow -AutoSize -AutoFilter -BoldTopRow -Show

In this example, we list all services on a computer, save the results as an Excel file on the current user’s desktop. Further we add some cool options:

  • $env:USERPROFILE\Desktop\services.xlsx places the file on the desktop for the current user.
  • -FreezeTopRow Freezes the top row in Excel so it sticks to the top.
  • -AutoSize adjusts the columns in the Excel file to adjust to the width of the widest content.
  • -AutoFilter Adds filtering to each row so they are easier to sort.
  • -BoldTopRow makes the top row in bold text.
  • -Show opens the Excel file right after it is saved.
PowerShell export to Excel xlsx format with ImportExcel module

If you would like to learn more you can check out these videos or visit the official project here.

Leave a Reply

Your email address will not be published. Required fields are marked *