private/Invoke-RetryRequest.ps1
function Invoke-RetryRequest { [CmdletBinding()] param ( [Parameter(ValueFromPipelineByPropertyName)] [string] $method = 'get', [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string] $uri, [Parameter(ValueFromPipelineByPropertyName)] [object] $body ) $sleepDuration = 0 $retry = $false $headers = Get-MdeAuthorizationHeader do { try { $retry = $false if (@('put', 'patch', 'post') -contains $method.ToLower()) { return Invoke-RestMethod -Method $method -Headers $headers -Uri $uri -Body $body } else { return Invoke-RestMethod -Method $method -Headers $headers -Uri $uri } } catch { if ($error[0].Exception.Response.StatusCode.value__ -ne 429) { $retry = $false; Write-Error $error[0].Exception; break } $sleepDuration = $sleepDuration -eq 0 ? 4 : $sleepDuration * 2 $retry = $true Write-Verbose "Retrying in $sleepDuration seconds" Start-Sleep -Seconds $sleepDuration } } until ( -not $retry ) } # SIG # Begin signature block # MIIVigYJKoZIhvcNAQcCoIIVezCCFXcCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUPX9r7knfXVwCOsAmSNrzWPNY # Na+gghHrMIIFbzCCBFegAwIBAgIQSPyTtGBVlI02p8mKidaUFjANBgkqhkiG9w0B # AQwFADB7MQswCQYDVQQGEwJHQjEbMBkGA1UECAwSR3JlYXRlciBNYW5jaGVzdGVy # MRAwDgYDVQQHDAdTYWxmb3JkMRowGAYDVQQKDBFDb21vZG8gQ0EgTGltaXRlZDEh # MB8GA1UEAwwYQUFBIENlcnRpZmljYXRlIFNlcnZpY2VzMB4XDTIxMDUyNTAwMDAw # MFoXDTI4MTIzMTIzNTk1OVowVjELMAkGA1UEBhMCR0IxGDAWBgNVBAoTD1NlY3Rp # Z28gTGltaXRlZDEtMCsGA1UEAxMkU2VjdGlnbyBQdWJsaWMgQ29kZSBTaWduaW5n # IFJvb3QgU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