...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="my_Agent" stop_on_error="no"> <settings > <log_level ><![CDATA[debug1]]></log_level> </settings> <script language="powershell"> <![CDATA[ # Use Write-Host, Write-Output or Echo cmdlets to write to the JobScheduler log Write-Host "job: this is some output" Write-Output "job: this is some output" echo "job: this is some output" # Standard PowerShell verbose setting is considered for log output $VerbosePreference = "Continue" # In addition the current log level of the job has to be set, i.e. log level "debug1" or higher logs verbose output Write-Verbose "job: this is some verbose output" # Standard PowerShell debug setting is considered for log output $DebugPreference = "Continue" # In addition the current log level of the job has to be set, i.e. log level "debug3" or higher logs debug messages Write-Debug "job: this is some debug output" # creates a warning for the job Write-Warning "job: this is a warning" # can be used to throw an error Write-Error "job: this is an error" ]]> </script> <run_time /> </job> |
Explanations
- Using PowerShell standard output
- Use of the
Write-Host
,Write-Output
andEcho
cmdlets is applicable.
- Use of the
- Using PowerShell verbose output
- The standard PowerShell verbosity setting is considered for log output if the job is configured for a log level
debug1
or higher. - Use
$VerbosePreference = "Continue"
- Subsequently use the
Write-Verbose
cmdlet.
- The standard PowerShell verbosity setting is considered for log output if the job is configured for a log level
- Using PowerShell debug messages
- The PowerShell debug setting is considered for log output in jobs if the job is is configured for a log level
debug3
or higher. - Use
$DebugPreference = "Continue"
- Subsequently use the
Write-Debug
cmdlet.
- The PowerShell debug setting is considered for log output in jobs if the job is is configured for a log level
- Using PowerShell Warnings
- Warnings are created by use of the
Write-Warning
cmdlet. Such warnings create cause corresponding warnings in the JobScheduler Master that are visible from the log and that might trigger a notification by e-mail.
- Warnings are created by use of the
- Using PowerShell Error Messages
- Use of the
Write-Error
cmdlet will create raise a job error that is visible from the log and that triggers subsequent actions as e.g. notification by e-mail, stopping the job, suspending an order etc.
- Use of the
...
Info |
---|
|
The JobScheduler PowerShell CLI module is available for PowerShell jobs. A basic job using the PowerShell CLI might look like this:
...
- The PowerShell CLI is activated by the
Import-Module JobScheduler
command. - For a complete list of cmdlets available from the PowerShell CLI see PowerShell CLI 1.1 - Cmdlets
Additional examples are available from the PowerShell CLI 1.1 - Use Cases article.
Parameter Handling
...
- to specify alias names for cmdlets,
- to specify global variables, e.g. paths, that can be used by all jobs,
- to import PowerShell modules, e.g. to specify
Import-Module JobScheduler
for use of the PowerShell CLI - to specify the behavior in case of errors by use of the
$ErrorActionPreference variable
- A value
$ErrorActionPreference = "Continue"
(Default) allows a PowerShell script to continue after an error occurred. It is up to the script developer to check for errors, e.g. by use of exceptions. - A value
$ErrorActionPreference = "Stop"
is the recommended setting as it immediately stops execution of the script after an error occurred.
- A value
Error Handling
PowerShell jobs offer a number of options to detect run-time errors.
...