Retry with exponential backoff
PowerShell
function Invoke-WithRetry {
param(
[scriptblock]$Action,
[int]$Attempts = 3,
[int]$BaseDelayMs = 500
)
for ($i = 1; $i -le $Attempts; $i++) {
try {
return & $Action
}
catch {
if ($i -eq $Attempts) { throw }
Start-Sleep -Milliseconds ($BaseDelayMs * [math]::Pow(2, $i - 1))
}
}
}