Let’s say you have a powershell script that you’ve developed and it requires some runtime variable, or specific snapins, and you want to make certain that your script doesn’t skip line 20 if line 15 has a null value for a variable etc…

You can actually add the parameter ​$ErrorActionPreference = “” to your code.

The Parameter can except 4 difference values which are:

Continue (this is the default value and what you get if you don’t include this parameter in your script at all)
SilentlyContinue
Inquire
Stop

In my scenario I was working with a custom script and everytime it’d try to load a powershell snap in that was already loaded in my profile, the entire script would die, because my parameter was set as this.

$ErrorActionPreference = “Stop”

I quickly modified it to $ErrorActionPreference = “Inquire”

This way I could see what things it was erroring on, and choose to Halt, or continue on with the script.

A great blog post to follow is here http://tasteofpowershell.blogspot.com/2008/07/handling-errors-in-powershell.html

(212)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.