VMware Stats Oneliner
Today’s oneliner is a nifty little function that reports the average CPU and Memory usage for one or more of your VMs, calculated over the last x 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)}}
}
A great way to use it is like this:
Get-VMStat (Get-VM) -Hours 4 | Where {$_.CPU -gt 50 -or $_.MEM -gt 75}
I’m sure you can figure out what that does. Be the first to give the correct answer in the comments to win everlasting glory! (or at least until the next oneliner…)
Enjoy!
3 Responses to VMware Stats Oneliner
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





[...] paste the Get-VMStat cmdlet in your [...]
Would it be possible to get the average CPU utilization for a cluster over a specific time period?
Thanks,
Marc
Is it possible to just get the average CPU and Memory utilization for a list of vms?