Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

when process reach high cpu kill it and start a service automatically

$
0
0

Hi all

im new to powershell and i need help for a script that i need that will do the following:

when process reach high CPU  kill it and start a service automatically. i created the following script with the example that the "notepad" is the process to kill and "fax" is the service to start immediately when the process "notepad" is killed. does the script correct?

$cpuutil=(get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 5 |
    select -ExpandProperty countersamples | select -ExpandProperty cookedvalue | Measure-Object -Average).average

If ($cpuutil -ge 90)
{Get-Process notepad | Stop-Process -Force Start-Service  fax}
Else
{Exit}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>