Get CPU usage

Posted:  June 24, 2015

Get CPU usage and inform the admin if it is at normal, high or critical level.

$WARNLEVEL = 25
$CRITLEVEL = 80

$cpuusage = (Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average)

if ( ($cpuusage.average) -lt $WARNLEVEL ) {
	Write-Host "[OK] CPU usage is normal: "($cpuusage.average)"%"
	exit 0
}
elseif ( ($cpuusage.average) -gt $CRITLEVEL ) {
	Write-Host "[PROBLEM] CPU usage is high: "($cpuusage.average)"%"
	exit 2
}
else {
	Write-Host "[WARNING] CPU usage is getting high: "($cpuusage.average)"%"
	exit 1
}