Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force ErrorActionPreference when running PowerShell?

We use PowerShell for some of our automated build scripts. Unfortunately, by default, PowerShell continues after an error.

Ordinarily, I can change this behaviour by setting $ErrorActionPreference = Stop.

I can't see a corresponding command line switch for PowerShell.exe, and we (deliberately) run the commands with -noprofile, so I can't put it in there.

How do I do this for a build script?

like image 568
Roger Lipscombe Avatar asked Jun 11 '26 05:06

Roger Lipscombe


1 Answers

Put it at the top of the script you're running?

$ErrorActionPreference = 'Stop'

Alternatively, you can also get similar control at the cmdlet level using the ErrorAction parameter.

like image 129
Shay Levy Avatar answered Jun 13 '26 14:06

Shay Levy