Getting results out of the console — to a spreadsheet, a file, or a clean table.
Export to CSV
Get-Process | Select-Object Name, Id, CPU |
Export-Csv -Path .\procs.csv -NoTypeInformation -Encoding UTF8
-NoTypeInformation drops the #TYPE header line; -Encoding UTF8 keeps non-ASCII intact (and is
the default in PowerShell 7).
Append to an existing CSV
Get-Service | Select-Object Name, Status | Export-Csv .\svc.csv -NoTypeInformation -Append
To plain text or JSON
Get-Process | Out-File .\procs.txt # plain text (as displayed)
Get-Service | ConvertTo-Json | Out-File .\svc.json # JSON
Clean on-screen table
Get-Service | Where-Object Status -eq 'Running' |
Format-Table Name, DisplayName, StartType -AutoSize
Add a calculated column (e.g. size in MB)
Get-ChildItem *.log | Select-Object Name,
@{Name='MB'; Expression={ [math]::Round($_.Length / 1MB, 2) }}
Re-import a CSV later
Import-Csv .\procs.csv | Where-Object { [int]$_.CPU -gt 10 }
Notes: use Export-Csv for data you’ll reopen or process (it preserves columns); use Out-File
only for the visual output. Don’t pipe Format-Table into Export-Csv — Format-* emits
formatting objects, not data, so the CSV comes out garbled. Select your columns first, format
last. Import-Csv reads everything back as strings, so cast ([int], [datetime]) before math.