The simplest way to retry in PowerShell
$attempt = 0 do { try { Do-SomeThing-That-May-Crash-Here $success = $true } catch { if ($attempt -eq 5) { throw } Write-Host "Task failed. Attempt $attempt. Will retry in next $(5 * $attempt) seconds. Error: $($Error[0])" -ForegroundColor Yellow Start-Sleep -Seconds $(5 * $attempt) } $attempt++ } until($ …