How to export data to Excel in PowerShell without Office
Exporting data to Excel in PowerShell is one of the handiest tasks for anyone who builds reports and automates data routines. With the ImportExcel module you can generate ready-formatted .xlsx files straight from your objects, without having Microsoft Excel or Office installed on the machine — perfect for sharing results with colleagues who live in spreadsheets. Here is how to do it, step by step and with examples ready to copy.
Prerequisites
- PowerShell 5.1 or PowerShell 7 (Windows, macOS or Linux).
- An Internet connection to install the module from the PowerShell Gallery.
- Permission to install modules for the current user (no administrator needed).
Step 1: Install the ImportExcel module
The first step to export data to Excel in PowerShell is to install the module, which is available for free on the PowerShell Gallery. Use -Scope CurrentUser so you do not need administrator privileges:
Install-Module -Name ImportExcel -Scope CurrentUser
# Confirmar que ficou instalado
Get-Module -ListAvailable ImportExcel
If this is your first time installing modules, PowerShell may ask you to trust the repository; answer Yes or add -Force. You do not need to run Import-Module manually: the module loads automatically as soon as you use one of its commands.
Step 2: Prepare the data to export
Any collection of objects works as a source: the result of a Get-Process, the rows of a CSV file, records from a database, or a list you build by hand. Each property of the object becomes a column and each object becomes a row. For this example, we will create a small list of products:
$dados = @(
[PSCustomObject]@{ Produto = "Teclado"; Quantidade = 12; Preco = 19.90 }
[PSCustomObject]@{ Produto = "Rato"; Quantidade = 8; Preco = 12.50 }
[PSCustomObject]@{ Produto = "Monitor"; Quantidade = 4; Preco = 149.00 }
)
Step 3: Create the Excel file with Export-Excel
The core command is Export-Excel. Just send the data through the pipeline and point to the destination file:
$dados | Export-Excel -Path "C:/Relatorios/produtos.xlsx" -WorksheetName "Produtos" -AutoSize
-AutoSize fits the column width to the content and -WorksheetName names the sheet. If the destination folder does not exist yet, create it first with New-Item -ItemType Directory -Path "C:/Relatorios", otherwise you get a path-not-found error. Running the command again on the same file updates the sheet with the latest data.
Tip: to write several tables into the same file, repeatExport-Excelwith a different-WorksheetName. Each name creates (or updates) a sheet, keeping everything tidy in a single .xlsx.
Step 4: Format as a table and highlight the header
For a more professional, easy-to-read result, turn the data into an Excel table, give it a title and freeze the first row. Using an options table (splatting) keeps the command readable:
$opcoes = @{
Path = "C:/Relatorios/produtos.xlsx"
WorksheetName = "Produtos"
AutoSize = $true
TableName = "Produtos"
TableStyle = "Medium6"
Title = "Relatório de Produtos"
BoldTopRow = $true
FreezeTopRow = $true
Show = $true
}
$dados | Export-Excel @opcoes
Here -TableName and -TableStyle apply a table style with automatic filters; -Title writes a title above the data; -BoldTopRow highlights the header and -FreezeTopRow keeps it visible as you scroll through many rows. Finally, -Show opens the file at the end (as long as you have Excel or another spreadsheet app installed).
Step 5: Read the data back with Import-Excel
The module is not only for writing: Import-Excel reads .xlsx files and returns objects you can filter, sort or reuse like any other in PowerShell — again, without needing Excel installed:
$lidos = Import-Excel -Path "C:/Relatorios/produtos.xlsx" -WorksheetName "Produtos"
$lidos | Where-Object { $_.Quantidade -gt 5 }
In this example we keep only the products whose quantity is greater than 5. It is the simplest way to connect spreadsheets to the rest of your automation.
Verify the result
Open the produtos.xlsx file in the folder you chose: you should see the three rows in a formatted table, with a bold header and adjusted columns. If you would rather check without opening Excel, run Import-Excel -Path "C:/Relatorios/produtos.xlsx" | Format-Table and confirm the same data appears in the console.
Conclusion
In just a few lines you went from PowerShell objects to a formatted Excel report, with no dependency on Office. From here you can schedule the script to generate reports automatically, combine several sheets in one file with -Append, or add charts. What will be the first report you automate this way?