Last active
May 29, 2017 23:47
-
-
Save tadcrazio/29792ffdfcdb6cea52b9b03c0d369566 to your computer and use it in GitHub Desktop.
Get CPU usage and top processes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-CpuUsage | |
{ | |
[cmdletbinding()] | |
Param() | |
$TopCPU = Get-Process | Sort-Object CPU -desc | Select-Object -first 10 | Format-Table -AutoSize CPU, ProcessName | |
$avg = Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Foreach {$_.Average} | |
if ($avg -ge 0) | |
{ | |
$CpuStatus = "OK" | |
} | |
elseif ($avg -ge 55 ) | |
{ | |
$CpuStatus = "Warning" | |
} | |
else | |
{ | |
$CpuStatus = "Critical" | |
} | |
$data = [pscustomobject] [ordered] @{ | |
Status = $CpuStatus | |
AverageCpu = $avg | |
} | |
$Data | Format-Table -AutoSize | Out-String | |
$TopCPU | Format-Table -AutoSize | Out-String | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment