not sure about the 'over 50 seconds' aspect, but you could poll to see if your CPU is over a certain limit.
Just a quick sketch in powershell...
# checks cpu threshold and runs script in $scriptName variable
function CPUthreshold
{
# mandatory single variable in function for script name
Param(
[Parameter(Mandatory=$true)]
[string]$scriptName
)
# cpu percentage limit
$limit = 50
# time to poll CPU limit in seconds
$pollTimeSec = 60
# check limit forever!
while($true){
# get the win32_processor object to get stats on the CPU
$cpu = Get-WmiObject win32_processor
# check if the CPU is over our limit
if ($cpu.LoadPercentage -gt $limit)
{
# call your script here!
& $scriptName
}
# wait again until the next poll
Start-Sleep -s $pollTimeSec
}
}
# call function with script name you want to run
CPUthreshold .\Hello-World.ps1
you could run this in a thread, or background the process as well on the machine you are interested in.