exit 1 inside irm | iex kills the user's terminal
exit codes · case
Affectspowershell 51, pwsh 7
Fails asTERMINAL KILLED
Mechanismiex session
Safe fixthrow not exit
Symptom
Section titled “Symptom”A user runs the documented one-liner irm https://example.com/install.ps1 | iex.
The installer hits an error path with exit 1 — and the user’s ENTIRE
interactive PowerShell session closes. No error message survives; the window is
just gone.
# In an interactive session:"exit 1" | iex # your terminal closes.# vspowershell -File failing.ps1 # child exits 1; your session survives.iex runs the script text in the CURRENT session, so exit terminates the
caller’s host — the interactive terminal for the copy-paste install flow. The
same script under -File gets its own process, where exit N is the correct
way to return a code. One script, two execution models, opposite semantics.
Workaround
Section titled “Workaround”- Fail with
throw(catchable, survivable underiex) instead ofexit. Under-File, an uncaught throw still yields a non-zero exit code. - The referenced fix replaced every error-path
exit 1with athrowin aStop-Installhelper, keeping both distribution modes correct — and pinned it with a throw-vs-exit contract test suite.