Skip to content

exit 1 inside irm | iex kills the user's terminal

exit codes · case

bothhard-errorinteractivescriptfirst-partyrepro: verifiediex-session
Affectspowershell 51, pwsh 7
Fails asTERMINAL KILLED
Mechanismiex session
Safe fixthrow not exit

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.

Terminal window
# In an interactive session:
"exit 1" | iex # your terminal closes.
# vs
powershell -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.

  • Fail with throw (catchable, survivable under iex) instead of exit. Under -File, an uncaught throw still yields a non-zero exit code.
  • The referenced fix replaced every error-path exit 1 with a throw in a Stop-Install helper, keeping both distribution modes correct — and pinned it with a throw-vs-exit contract test suite.