How to export output to excel in PowerShell?


As of now, there is no built-in command like CSV (Export-CSV) to export output to the excel file but we can use the Out-File command to export data to excel or any other file format.

Let’s use Out-File to export the output of the Get-Processes command to an excel file.

Get-Process | Out-File C:\Temp\processes.xls

The above command will get all the running processes on the local system to the excel file. Let’s check the output of the excel file. You can see that the output is not in the proper excel format.

One other way is to install the ImportExcel module for excel. It is a very popular module to work with excel files.

To install the ImportExcel module, you need to run the below command to get it installed from the PowerShell gallery.

Install-Module ImportExcel -AllowClobber -Force

Once you install it, you need to import the module in the current PowerShell session if not imported.

Get-Module ImportExcel -ListAvailable | Import-Module -Force -Verbose

Once you have this module loaded in PowerShell, you can run the below command to export output into the excel format.

Get-Process | Export-Excel -Path C:\Temp\Processes.xlsx

Output

Updated on: 01-Nov-2023

38K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements