Below is how I handle it:
$Global:_retryCount = 1000
$Global:_retryInterval = 10
for($retryAttempts=0; $retryAttempts -lt $Global:_retryCount; $retryAttempts++){
Try{
$ctx.ExecuteQuery()
break
}
Catch [system.exception]{
Start-Sleep -s $Global:_retryInterval
}
}
Does this actually work though?
ReplyDeleteI would imagine that after the first ExecuteQuery, the context would be lost and the retries wouldn't actually do anything.
It works well during my test. The content of $ctx is stored at client side.
DeleteI just encountered this issue. Might help me out! Will try and let you know how it goes!
ReplyDeleteWorks great. Thanks
ReplyDeleteI had this crop up recently as well when running a script to disable onedrive sync for all users in a tenant. This variation slowly increases the wait time for each request and gives up after 8 attempts.
ReplyDelete$retrySecs=1
$retryMax=8
$ErrorActionPreference = "Stop"
for($retryAttempts=0; $retryAttempts -lt $retryMax; $retryAttempts++){
Try{
Set-SPOUser -Site $onedrive.url -LoginName $SiteCollAdmin -IsSiteCollectionAdmin $true
break
} Catch [system.exception]{
Start-Sleep -s ($retryAttempts*$retrySecs)
}
}
Thanks for sharing! It's good.
Delete