PowerShell VM CSV Report


A customer via a colleague, Satinder Sharma, wanted to have a CSV output from Get-TintriVM. Their attempt was:

Get-TintriVM  | Export-Csv WS_inventory.csv

This does nothing.  After some experimentation and assistance from Dhruv Vermula, we have this:

Get-TintriVM | Select-Object {$_.vmware.name}, {$_.Uuid.UuId} | Export-csv vm2.csv

This works, but the columns are “$_.vmware.name” and “$_Uuid.Uuid”, which is not very friendly.  So I created created a small script, VmCsvReport, that is similar to a blog post “Obtain a VM CSV Report“.  This script creates nice columns; for example, “VM Name” instead of “$_.vmware.name” and creates a CSV file.

The script uses @{Expression} to create alias columns.

 $ex = @{Expression={$_.vmware.name};label="VM Name"},
       @{Expression={$_.stat.sortedstats.LatencyTotalMs};label="Total Latency"},
       @{Expression={$_.stat.sortedstats.LatencyNetworkMs};label="Network Latency"},
       @{Expression={$_.stat.sortedstats.LatencyStorageMs};label="Storage Latency"},
       @{Expression={$_.stat.sortedstats.LatencyDiskMs};label="Disk Latency"}

The output of Get-TintriVM is piped into Select-Object using the aliases in $ex.  Then $results is piped to the Export-Csv cmdlet to create a CSV file.  This could be done in one line, but I broke it up so that I could easily examine the output in debug.

$result = Get-TintriVM -TintriServer $conn | Select-Object $ex
$result | Export-Csv $csv_file

The specified VM information is in the CSV file which Excel can read quite easily.

Unfortunately, the columns are hard-coded in the script, because the PowerShell Toolkit does not have a cmdlet that maps the CSV download API.  I couldn’t suss-out a way to have configurable columns similar “Obtain a VM CSV Report“. If you know a way, please let me know.

Until next time,

– Rick –


One comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s