Why does a PowerShell script not end when there is a non-zero exit code using when using the call operator and $ErrorActionPerference = \"Stop\"
?
Using the
The return code is not a PowerShell error - it's seen the same way as any other variable.
You need to then act on the variable and throw
an error using PowerShell for you script to see it as a terminating error:
$ErrorActionPreference = "Stop"
& cmd.exe /c "exit 1"
if ($LASTEXITCODE -ne 0) { throw "Exit code is $LASTEXITCODE" }