Share via


PowerShell - Try/Catch/Retry

 # try/catch/fix and continue
 $tries = 0
 while ($tries -lt 2) {
    try {
      $tries++
      $ErrorActionPreference='Stop'
      # code I am testing goes here - perhaps with a param argument that needs changing
      $tries++
   }
   catch {
 #fixup code goes here
      $ErrorActionPreference='SilentlyContinue' # and the loop will now retry.  
   }
 }