Job Environment

The PowerShell environment in which the PowerShell job scripts are executed is pre-configured.
Before a job script is executed the following actions are performed:

  • powerVault and powerJobs modules are imported as well as all script modules in the module directory.

  • $workingDirectory variable of type DirectoryInfo specifies foreach job a unique temporary directory, located under C:\Temp\powerJobs Processor\.

  • $job variable of type powerVault Job is provided that represents the job that is currently being executed.

  • $host variable is extended with an Applications property that contains all registered Applications.

  • Setup_Job.ps1 script is invoked.

Setup_Job.ps1

The Setup_Job.ps1 file is a special script that is always executed before a job is executed.
It is recommended to only modify this script for actions that need to be performed before every job execution regardless of job type.
It is located in the products ProgramData directory %ProgramData%\coolOrange\powerJobs\Setup_Job.ps1

This script is responsible for setting up the following global variables:

Depending on the entity the Job was triggered for, the following objects are automatically created using the global $job variable:

With every job execution, temporary files from previous jobs are automatically removed from the working directory by using the Clean-Up cmdlet.

$ErrorActionPreference

When a script is executing in powershell.exe, the default behavior is to continue the execution of the script when an error occurs.
powerJobs handles Errors in scripts differently: the job execution is Stopped when an exception is thrown!

This default behaviour can be changed by using the $ErrorActionPreference variable:

$ErrorActionPreference = "Continue"

All the possible options are:

Identifier

Description

Continue

This is the default PowerShell 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 line.

SilentlyContinue

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.

Stop

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.

Inquire

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.

Warning: It is not recommended to use this option with powerJobs Processor!