I use PowerShell a lot. Sometimes to automate something with a script but often just to get some data. Export my results to a csv (Export-CSV) for example not always gets the result you want. Create your own table and you are more in control export it to a XML file and your ready to share it with anything or anyone.

.NET is easy to use in combination with PowerShell. I’ll tell you how to use the DataTable class. 

First we need to create a DataTable, we use a .NET class for that:

$dt = New-Object System.Data.Datatable "MyTableName"

Second we need to add some columns to the DataTable:


Now that we have a DataTable with some Columns we need to add some rows with data to it. Request some data (for example Get-Process), put the results in the row and add the row to the DataTable.

Get-Process | %{ $row = $dt.NewRow(); $row["Id"]=$_.Id; $row["ProcessName"]=$_.ProcessName; $dt.Rows.Add($row)}

The object $dt now contains everything we need. Type $dt and press enter to preview your data:


If you want to save this data to a XML file (which is very handy), you just have to use this method:


TIP: Open this XML file in Excel