PowerShell

Output results from PowerShell to CSV or XML

Have you wanted to output results from PowerShell to CSV or XML? Well I am going to show you how.

I have previously explained how to export results of PowerShell queries but did not include how to export the results to CSV or XML. The reason for that is that when you become familiar with PowerShell you will find out that PowerShell commands can return a lot more information than what they show on screen. I will show how to get that information in a future blog post but just be aware that there is a lot more information readily available and only the displayed columns are exported to text(TXT) files.

When exporting to CSV and XML the hidden columns are exported as well. I will give an example of the difference in the exports.

The results of Get-Process are displayed below.

1

If I run the below commands I would output the results of Get-Process to CSV and XML.

Get-Process | Export-CSV c:\PowerShell\ProcessCSV.csv

Get-Process | Export-CliXML c:\PowerShell\ProcessCliXML.xml

2

When you look in the text file you will see the same results as shown on screen.

3

However, the CSV and XML have all the columns available for the results of that command. I have shown an excerpt of the Get-Process results in CSV format below.

4

I would advise that you use TXT, CSV and XML files where appropriate and check out the results you could get from various commands.

Leave a Reply