Retry Logic

Simple Retry Logic Loop

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
$Stoploop = $false
[int]$Retrycount = "0"

do {
    try {
        Scripts Commands here
        Write-Host "Job completed"
        $Stoploop = $true
    }
    catch {
        if ($Retrycount -gt 3){
            Write-Host "Could not complete after 3 retrys."
            $Stoploop = $true
        }
        else {
            Write-Host "Could not complete retrying in 30 seconds..."
            Start-Sleep -Seconds 30
            $Retrycount = $Retrycount + 1
        }
    }
} While ($Stoploop -eq $false)
What's on this Page