PowerShell - Export-Csv versus Export-Clixml

1 min read · Updated 5 September 2024

Did this guide help you? You can support me by subscribing to the channel, sharing it, disabling your ad blocker or making a donation. Thank you!

Export-Csv is handy because it allows you to export and use the export in a spreadsheet like Excel or in PowerShell with Import-Csv.
The generated file also has the advantage of being readable.

# Example
Get-Process |
Select-Object -Property name,cpu,path |
Export-Csv -Path c:\process.csv
# Display the contents of the file
Get-Content -Path c:\process.csv
# Import the CSV
Import-Csv -Path C:\process.csv

But Export-Csv falls short under certain conditions.

Export-Csv

Get-Service |
Select-Object -Property name,dependentservices |
Export-Csv -Path c:\demo.csv
# Display the contents of the file
Get-Content -Path c:\demo.csv
# Import the CSV
Import-Csv -Path C:\demo.csv
# Display the type of the dependentservices property
(Get-Service).dependentservices.GetType()

The problem is that Export-Csv doesn’t know how to handle array properties (represented between braces).

If you want to export and import your objects in this context, it’s better to use Export-Clixml.

Export-CliXml

Get-Service |
Select-Object -Property name,dependentservices |
Export-Clixml -Path c:\process.xml
# Display the contents of the file
Get-Content -Path c:\process.xml
# Import the xml file
Import-Clixml -Path C:\process.xml

Unfortunately, it is no longer possible to use the file directly in a spreadsheet, and the generated file is difficult to read.

Related links

Follow me on

Support me

Buy Me a Coffee at ko-fi.com

New site · Reference

The Windows directory tree

Native Windows folders, files and logs: what they are for, what they contain, with commands and Microsoft sources.

Browse the tree

New site · Reference

Group Policy settings

ADMX settings for Windows 10, 11, Server and applications: registry keys, PowerShell commands and use cases.

Browse the policies