-
-
Save TheRockStarDBA/64e3c6faf0f8fa67bd9b354922e6d4da to your computer and use it in GitHub Desktop.
Powershell Exponential Backoff. Replace "Connect-ExchangeOnline" with whatever
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
for ($i=1;$i -le 5;$i++) { | |
try { | |
Connect-ExchangeOnline -Credential $Credential -Verbose:$false -ShowProgress $false -Force -WarningAction silentlycontinue 6>$null | |
} catch { | |
if ($i -ge 2) {Write-Warning "Connect-ExchangeOnline Retry $i"} | |
[float]$sleepTimer = [Math]::Pow(2,$i) + [float]((Get-Random -Max 1000) /1000 ) | |
Write-Warning "Connect-ExchangeOnline PS Remoting Error (retry: $sleeptimer sec): $PSItem" | |
Start-Sleep $sleeptimer | |
continue | |
} | |
} | |
if ($i -ge 5) {Write-Warning "Connect-ExchangeOnline backoff retry timer reached."} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment