Export-Csv cmdlet converts PowerShell objects into a comma-separated values file, and it’s one of the most commonly used cmdlets for turning script output into something you can open in Excel or hand off to someone else.
Basic Usage
Get-Process | Select-Object Name, Id, CPU | Sort-Object CPU -Descending | Export-Csv -Path "C:\Reports\processes.csv" -NoTypeInformationThis gets every running process, selects just the Name, Id, and CPU columns, sorts by CPU usage descending, and writes the result to a CSV file.
Useful Parameters
-NoTypeInformation— omits the “#TYPE” header line that PowerShell adds by default, which most other tools (including Excel) don’t expect.-Append— adds rows to an existing CSV instead of overwriting it, useful when a script runs on a schedule and you want a running log.-Delimiter ";"— some regional Excel settings expect semicolons instead of commas.-Encoding UTF8— worth setting explicitly if your data includes non-ASCII characters (accented names, currency symbols, non-English text); without it, older PowerShell versions can default to an encoding that mangles those characters when the file is reopened.-Force— overwrites a read-only file at the target path instead of failing with an access-denied error, useful in scheduled scripts writing to the same filename each run.
Import-Csv -Path "C:\Reports\processes.csv" cmdlet.
A Common Gotcha: Nested Objects
If a property you select holds a complex object rather than a simple value (for example, a group membership list or a nested settings object),Export-Csv doesn’t flatten it — it just writes the object’s type name (like System.Object[]) into the cell instead of anything useful. Convert those properties to a plain string first, typically with -join, before piping to Export-Csv:
Get-ADUser -Filter * -Properties MemberOf | Select-Object Name, @{Name='Groups';Expression={$_.MemberOf -join '; '}} | Export-Csv -Path "C:\Reports\users.csv" -NoTypeInformation
That calculated property joins the group list into a single readable string per row instead of a broken type-name placeholder.
Resources
- Windows Admin Center – WSUS/SCCM Update Category Explained
- Browse our Windows Admin Toolkit picks on Amazon
Discover more from TechyGeeksHome
Subscribe to get the latest posts sent to your email.