Powershell - Export-Csv versus Export-Clixml

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make 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 declares forfeit 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