Created
March 8, 2019 16:59
-
-
Save renzors/8fd5cec6e6891b85dd9e16c320e4b7f9 to your computer and use it in GitHub Desktop.
PS script to retry
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
$retries = 3 #$OctopusParameters['appPoolCheckRetries'] | |
$delay = 1000 #$OctopusParameters['appPoolCheckDelay'] | |
$counter = 1 | |
do { | |
try { | |
#Script Here | |
Break | |
} catch { | |
Write-Error $_.Exception.InnerException.Message -ErrorAction Continue | |
Write-Host "Attemp $counter failed." | |
Write-Host "Waiting for $delay milliseconds and retrying again..." | |
Start-Sleep -Milliseconds $delay | |
$counter++ | |
} | |
} while ($counter -le $retries) | |
if($counter -ge $retries) { | |
throw "Could not run script properly. `nTry to increase the number of retries ($retries) or delay between attempts ($delay milliseconds)." } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment