Quantcast
Channel: TechNet Blogs
Viewing all articles
Browse latest Browse all 36188

PowerShell – Try/Catch/Retry

$
0
0

 # 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.
}
}

 


Viewing all articles
Browse latest Browse all 36188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>