Output results from PowerShell to CSV or XML — Parv The IT Geek

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.

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

Get-Process | Export-CSV c:PowerShellProcessCSV.csv

Get-Process | Export-CliXML c:PowerShellProcessCliXML.xml

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

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.

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

Originally published at https://parvtheitgeek.com on February 23, 2014.


Published by Parvinder Nijjar

I blog at ParvTheITGeek.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: