VMware Cloud Community
ablej
Hot Shot
Hot Shot

Help with Creating Report

I am trying to use the following code to export VM hard disk size to a Excel file. The script is from the VI toolkit blog.

$datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}

$diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}

get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property datastore,"Total Disk" -

Any help is greatly appreciated

David Strebel www.david-strebel.com If you find this information useful, please award points for "correct" or "helpful"
0 Kudos
1 Reply
LucD
Leadership
Leadership

Powershell has a handy cmdlet, called Export-Csv, that does exactly that.

You pipe the results to this cmdlet, specify a filename and that's it.

$datastoreExp = @{N="Datastore"; E={ ($_ | get-datastore | select-object -first 1).Name }}
$diskSizeExp = @{N="Total Disk"; E={ ($_ | get-harddisk | measure-object -property CapacityKB -sum).Sum }}
get-vm | select Name, $datastoreExp, $diskSizeExp | sort -property datastore,"Total Disk" | Export-Csv c:\test.csv

The beauty of Powershell Smiley Wink


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos