kprobst kprobst - 2 months ago 10
PowerShell Question

Terminating a script in PowerShell

I've been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function. For example:

function foo() {
# Do stuff that causes an error

Of course there's no such thing as
. There is
, but this actually closes the console window, which is not what I want. What I need is something equivalent to Python's
that will simply stop execution of the current script without further adieu.

Edit: Yeah, it's just
. Duh.


You should use the exit keyword.