Free Physical Memory using powershell
Posted: Fri Dec 24, 2021 4:42 am
Hi,
Currently we are using the below powershell script to get the Top 5 CPU consuming process when the CPU load is meeting the Threshold.
Try {
$Threshold1 = 90
$Threshold2 = 95
$CpuLoad = (Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average ).Average
IF($CpuLoad -gt $Threshold1) {
Write-Output (Get-Process | Sort -Descending CPU | Select -First 5)
}elseif($CpuLoad -gt $Threshold2) {
Write-Output (Get-Process | Sort -Descending CPU | Select -First 5)
} Else {
Write-Host "CPU load is" $CpuLoad "%"
}
}
Catch {
Write-Host "Script Check Failed"
}
Now we have a new requirement. i.e., When the Physical memory is like 90 or 95 we need to get top 5 memory consuming process.
could you please help with the requirement.
Thanks in advance.
Currently we are using the below powershell script to get the Top 5 CPU consuming process when the CPU load is meeting the Threshold.
Try {
$Threshold1 = 90
$Threshold2 = 95
$CpuLoad = (Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average ).Average
IF($CpuLoad -gt $Threshold1) {
Write-Output (Get-Process | Sort -Descending CPU | Select -First 5)
}elseif($CpuLoad -gt $Threshold2) {
Write-Output (Get-Process | Sort -Descending CPU | Select -First 5)
} Else {
Write-Host "CPU load is" $CpuLoad "%"
}
}
Catch {
Write-Host "Script Check Failed"
}
Now we have a new requirement. i.e., When the Physical memory is like 90 or 95 we need to get top 5 memory consuming process.
could you please help with the requirement.
Thanks in advance.