Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ErrorAction Stop by default in PowerShell scripts

Tags:

powershell

How can I set in a PowerShell script that all the actions have the property ErrorAction set to Stop?

P.S.: Powershell 2.0

like image 947
toscanelli Avatar asked Sep 13 '26 13:09

toscanelli


1 Answers

Set the $ErrorActionPreference for the script to stop:

$ErrorActionPreference = "Stop"

edit: As ivan-mirchev pointed out, of course this change is not permanet and only active in the runspace where the code is executed. When you open a new Powershell session it will have the default value of $ErrorAction = 'Continue'

like image 169
T-Me Avatar answered Sep 15 '26 10:09

T-Me



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!