3

We use PowerShell for some of our automated build scripts. Unfortunately, by default, PowerShell continues after an error.

Ordinarily, I can change this behaviour by setting $ErrorActionPreference = Stop.

I can't see a corresponding command line switch for PowerShell.exe, and we (deliberately) run the commands with -noprofile, so I can't put it in there.

How do I do this for a build script?

2 Answers 2

2

Put it at the top of the script you're running?

$ErrorActionPreference = 'Stop'

Alternatively, you can also get similar control at the cmdlet level using the ErrorAction parameter.

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

2 Comments

That means editing every single script. I'd prefer to find a global solution.
Have you checked @Marcus' solution? I can offer a solution but it would affect all users.
2

There doesn't seem to be a way to set:

powershell -erroractionpreference stop ...

The following would work:

powershell -command { $ErrorActionPreference = "stop"; .\test.ps1 } -noprofile

There is of course nothing to stop the script (re)setting ErrorActionPreference.

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.