Powerjobs handles errors in scripts differently from the normal PowerShell execution. When a script is executing in
, the default
behavior is to
the execution of the script when an error occurs in one of the commands. In
the errorhandling is changed so
is thrown if an error occurs.
If you want to handle errors yourself in your script you can use PowerShell's built in exception mechanism and use
blocks, or you can
change the error handling behavior of PowerShell by changing the value of the
This is the default preference setting. The
error object is written to the output pipe and
added to $error, and $? is set to false.
Execution then continues at the next script
When this action preference is set, the error
message is not written to the output pipe
before continuing execution. Note that it is
still added to $error and $? is still set to false.
Again, execution continues at the next line.
This error action preference changes an
error from a non-terminating error to a
terminating error. The error object is thrown
as an exception instead of being written to
the output pipe. $error and $? are still
updated. Execution does not continue.
Prompts the user requesting confirmation
before continuing on with the operation.. At
the prompt, the user can choose to continue,
stop or suspend the operation.
Changing $ErrorActionPreference value
To change the value of the $ErrorActionPreference e.g. to "Continue" you can use the following statement:
$ErrorActionPreference = "Continue"
You can use the numeric value as well
If the exception is not caught in your script the script will be cancelled and the exception will be caught in the powerJobs dll. The job will
fail and an error message will be written to the log.
In powerJobs it is not recommended to use "Inquire" or numeric value 3.