Run a scheduled task if memory usage goes above 90%

0

Is it possible on Windows to use task scheduler or other methods to run a script if the memory usage on the device goes above a certain level?

john doe

Posted 2019-11-12T16:07:11.637

Reputation: 131

Answers

1

PowerShell might work well for this. You could schedule something like this to run every so often to check memory and then run your script. If you already have a script you just have to add '& PathTo\yourscript.bat' into the if statement.

$memory = gwmi -Class win32_operatingsystem -computername localhost | 
Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N0}” -f 
((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ 
$_.TotalVisibleMemorySize)}} 

$memoryUsage = [int]$memory.MemoryUsage

#if usage over 90% do something
if ($memoryUsage -gt 90){
    echo "script goes here"
}

dno

Posted 2019-11-12T16:07:11.637

Reputation: 66