# Andy Hill # http://virtualandy.wordpress.com/2009/02/05/get-vmstat-and-resource-allocation/ # Required: VI Toolkit # Retrieve average CPU and RAM for specified VMs for elapsed period in hours function Get-VMStat { param( $VM,[Int32]$Hours = 1 ) $VM | Sort Name | Select Name, @{N="CPU";E={[Math]::Round((($_ | Get-Stat -Stat cpu.usage.average -Start (Get-Date).AddHours(-$Hours) -IntervalMins 5 -MaxSamples ($Hours*12) | Measure-Object Value -Average).Average),2)}}, @{N="MEM";E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-$Hours) -IntervalMins 5 -MaxSamples ($Hours*12) | Measure-Object Value -Average).Average),2)}} } #Example Usage # you will be asked for your VC server # PS> Get-VC # PS> Get-VMStat (Get-VM) -Hours 2160