Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TheRockStarDBA/64e3c6faf0f8fa67bd9b354922e6d4da to your computer and use it in GitHub Desktop.
Save TheRockStarDBA/64e3c6faf0f8fa67bd9b354922e6d4da to your computer and use it in GitHub Desktop.
Powershell Exponential Backoff. Replace "Connect-ExchangeOnline" with whatever
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