Powershell try/catch/finally -


i wrote powershell script works great - however, i'd upgrade script , add error checking / handling - i've been stumped @ first hurdle seems. why won't following code work?

try {   remove-item "c:\somenonexistentfolder\file.txt" -erroraction stop }  catch [system.management.automation.itemnotfoundexception] {   "item not found" }  catch {   "any other undefined errors"   $error[0] }  {   "finished" } 

the error caught in second catch block - can see output $error[0]. catch in first block - missing? thanks

-erroraction stop changing things you. try adding , see get:

catch [system.management.automation.actionpreferencestopexception] { "caught stopexecution exception"  $error[0] } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -