2

In my PowerShell script I'm calling some command line tools (not cmdlets) that may output error text and set errorlevel nonzero on error conditions. I'd like any error from any of these tools to abort my script.

What's the best way to do this?

Is there a way to have PowerShell automatically check $? and stderr after every command and throw an exception? I was thinking something along the lines of "on error" that 4NT or VBScript has - a global watch. Not very object-orienty, so I was hoping PowerShell had something better.

[Edit: last couple questions moved to here.]

1
  • Scott, I would make the last two questions a separate question. Commented Jun 19, 2009 at 13:08

1 Answer 1

1

You will need to either write a function to do this or within the script constantly check for the errorlevel.

Some information on a function to do this is at:

http://www.eggheadcafe.com/conversation.aspx?messageid=31829234&threadid=31829225

and other useful information can be found on the windows powershell blog.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.