Я хочу создать цикл в своем сценарии Powershell, который будет работать в течение определенного количества секунд, возможно ли это?
Вот что у меня есть до сих пор, не уверен, что это правильно. Я надеялся на более простой способ сделать это. Является ли это возможным?
function collectProcess {
param (
#processnamn
$process,
#limit for the WS
$limit,
#Amount of seconds the loop will run
$length
)
#Creating a new time span with the amount of seconds given
$timeout = new-timespan -Seconds $length
#starting a timer to compare later with the timeout
$timer = [diagnostics.stopwatch]::StartNew()
while ($timer.elapsed -lt $timeout) {
$tempProcess= Get-Process -Name $process
if ($tempProcess.WS -gt $limit) {
Stop-Process -Name $process -Force
Write-Host ("Process has stopped now"+ " The WS is: "+ $tempProcess.WS + " and our limit is: "+$limit )
break;
}
}
}
Версия PowerShell: 5.1
sleep 1
в цикле, чтобы вырубить процессор. - person js2010   schedule 17.05.2020