
📎 This article includes 3 downloadable practice files ↓
“`powershell
$orders = Import-Csv .\sales.csv | Select-Object *, @{ n = “amount”; e = { [int]$_.qty * [int]$_.rate } }
$summary = $orders | Group-Object region | ForEach-Object {
[pscustomobject]@{ region = $_.Name; orders = $_.Count; sales = ($_.Group | Measure-Object amount -Sum).Sum }
} | Sort-Object sales -Descending
$summary | Export-Csv region_summary.csv -NoTypeInformation
“`
Calculated properties (@{ n = ...; e = { ... } }) add columns; [pscustomobject] builds clean result rows.
Real Excel files
The community ImportExcel module (Install-Module ImportExcel -Scope CurrentUser) reads and writes .xlsx without Excel installed: Export-Excel report.xlsx -AutoSize -TableName Sales.
Practice
Run the script next to sales.csv and open the summary file it saves.
📎 Practice files for this article
- 🖥️ps-05-csv-excel.ps1Lesson code file.⬇ PS1 · 546 B
- 🧾sales.csv40 sample orders used by the scripts.⬇ CSV · 1 KB
- 📄ps-05-csv-excel-output.txtOutput from our test run.⬇ TXT · 187 B
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.