Last active
September 8, 2021 17:09
-
-
Save JustinGrote/0f1ed01cf8a6684e82812cbe2013b04d 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