Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active September 8, 2021 17:09
Show Gist options
  • Select an option

  • Save JustinGrote/0f1ed01cf8a6684e82812cbe2013b04d to your computer and use it in GitHub Desktop.

Select an option

Save JustinGrote/0f1ed01cf8a6684e82812cbe2013b04d to your computer and use it in GitHub Desktop.

Revisions

  1. JustinGrote revised this gist Jul 3, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ExponentialBackoffDemo.ps1
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    for ($i=1;$i -le 5;$i++) {
    try {
    Connect-ExchangeOnline -Credential $SeasonsAADCredential -Verbose:$false -ShowProgress $false -Force -WarningAction silentlycontinue 6>$null
    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 )
  2. JustinGrote created this gist Jul 3, 2020.
    12 changes: 12 additions & 0 deletions ExponentialBackoffDemo.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    for ($i=1;$i -le 5;$i++) {
    try {
    Connect-ExchangeOnline -Credential $SeasonsAADCredential -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."}