Is there an elegant Powershell script setting that would exit the running Powershell script (or shell instance) if a program fails?
I'm imagining something like Bash feature set -o errexit (or set -e) but for Powershell. In that feature, if a program in the bash script fails (process return code was not 0) then the bash shell instance immediately exits.
In powershell, the script could check $LastExitCode. However, that becomes cumbersome to do for every program call. Maybe powershell has a feature to automatically check and react to program return codes.
To explain in a script
Set-Powershell-Auto-Exit 'ProgramReturnCode' # what should this be?
& program.exe --fail # this program fails with an error code
& foo.exe # this never runs because script has exited