Friday, October 17, 2008

List vm usage and assosiated datastore

Hi all,
 
in a fairly large environment the tracking of a VM's Disk usage and the datastore on who i resides i a trivial task.
 
$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"
 This small PowerShell script pulls a list of all VMs and the disk ussage pr. vm and on witch datastore it is connected to/placed. Be aware if an iso is mounted from a datastore this will generate an aditional entry for the VM in question.