SOLVED

Azure Function Apps - PowerShell's ErrorActionPreference

Copper Contributor

By default the environment's $ErrorActionPreference is set to 'Continue'. When a cmdlet throws an error the script will continue.

 

I want it to 'Stop' and get caught in the catch of my try-catch block. In my script I am able to set:

 

$ErrorActionPreference = "Stop"

 

and if I print the value to the screen I can see that  it is now set to 'Stop' and not 'Continue'. However, when my cmdlet throws an error it still continues. It is ignoring my error action preference and behaving according to the default value.

 

Can anyone shed any light on this?

1 Reply
best response confirmed by ray hogan (Copper Contributor)
Solution

I was able to get it to behave by using:

 

$global:erroractionpreference = 1

Instead of

 

$ErrorActionPreference = 'Stop'

Robot LOL

 

1 best response

Accepted Solutions
best response confirmed by ray hogan (Copper Contributor)
Solution

I was able to get it to behave by using:

 

$global:erroractionpreference = 1

Instead of

 

$ErrorActionPreference = 'Stop'

Robot LOL

 

View solution in original post