Visitors

PowerCLI: Average CPU, Memory, Network and Disk usage

This simple PowerShell/PowerCLI script calculates the average CPU, Memory, Network and Disk usage for powered on virtual machines over the last 30 days, 5 minutes interval.

Amend ‘AddDays(-N)‘ and ‘-IntervalMins 5‘ if needed.

Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Select Name, Host, NumCpu, MemoryMB, `
@{N="CPU Usage (Average), Mhz" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}, `
@{N="Memory Usage (Average), %" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} , `
@{N="Network Usage (Average), KBps" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} , `
@{N="Disk Usage (Average), KBps" ; E={[Math]::Round((($_ | Get-Stat -Stat disk.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} |`
Export-Csv -Path d:AverageUsage.csv

Example of the script output:

Name Host NumCpu MemoryMB CPU Usage (Average), Mhz Memory Usage (Average), % Network Usage (Average), KBps Disk Usage (Average), KBps
dsva02 esxc02n02.vStrong.local 2 2048 61.91 5.63 28.7 17
VSR001 esxc02n01.vStrong.local 2 4096 63.66 9.7 6.86 15.11
SQL100 esxc02n02.vStrong.local 2 8192 40.64 2.67 0.07 3.75
VCS001 esxc02n03.vStrong.local 2 8192 177.84 5.59 0.14 15.53
VCS002 esxc02n02.vStrong.local 2 8192 36.47 1.85 0.09 6.14

I hope you find this useful.

9 comments to PowerCLI: Average CPU, Memory, Network and Disk usage

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>