Export-Csv
Write objects to a CSV file
Get-ChildItem -File | Select-Object Name, Length | Export-Csv -Path .\files.csv -NoTypeInformation
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Export-Csv
- PowerShell 5.1 Writes ASCII by default, so accented names turn into ?. Add -Encoding UTF8.
- PowerShell 7 Writes UTF-8 by default, and -NoTypeInformation is no longer needed (it is the default).
Writes a CSV. -NoTypeInformation drops the #TYPE header (needed in Windows PowerShell 5.1). In PowerShell 7 that is already the default.
Select the properties you want first. Do not export formatted objects.
Try this
Get-Process | Select-Object -First 5 Name, Id | Export-Csv -Path .\procs.csv -NoTypeInformation