kprobst kprobst - 1 year ago 147
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.

Answer Source

You should use the exit keyword.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download