Skip to content

Instantly share code, notes, and snippets.

@renzors
Created March 8, 2019 16:59
Show Gist options
  • Save renzors/8fd5cec6e6891b85dd9e16c320e4b7f9 to your computer and use it in GitHub Desktop.
Save renzors/8fd5cec6e6891b85dd9e16c320e4b7f9 to your computer and use it in GitHub Desktop.
PS script to retry
$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