-
-
Save yasinai/a06539cae19f352a05736c83b9ed11d8 to your computer and use it in GitHub Desktop.
Timeout in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Version 2 | |
$maximumRuntimeSeconds = 3 | |
$process = Start-Process -FilePath powershell.exe -ArgumentList '-Command Start-Sleep -Seconds 4' -PassThru | |
try | |
{ | |
$process | Wait-Process -Timeout $maximumRuntimeSeconds -ErrorAction Stop | |
Write-Warning -Message 'Process successfully completed within timeout.' | |
} | |
catch | |
{ | |
Write-Warning -Message 'Process exceeded timeout, will be killed now.' | |
$process | Stop-Process -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment