Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The following sample job explains how to use output channels for PowerShell such as:


 

Code Block
languagepowershell
titlePowerShell Job with different output channels
collapsetrue
<?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 consideredused for log output
$VerbosePreference, consider script scope when modifying this variable
$script: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 consideredused for log output
$DebugPreference, consider script scope when modifying this variable
$script: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

  1. Using PowerShell standard output
    • Use of the Write-HostWrite-Output and Echo cmdlets is applicable.
  2. 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 $script:VerbosePreference = "Continue" 
    • Subsequently use the Write-Verbose cmdlet.
  3. Using PowerShell debug messages
    • The PowerShell debug setting is considered for log output in jobs if the job is configured for a log level debug3 or higher.
    • Use $DebugPreference $script:DebugPreference = "Continue"
    • Subsequently use the Write-Debug cmdlet.
  4. Using PowerShell Warnings
    • Warnings are created by use of the Write-Warning cmdlet. Such warnings cause corresponding warnings in the JobScheduler Master that are visible from the log and that might trigger a notification by e-mail.
  5. Using PowerShell Error Messages
    • Use of the Write-Error cmdlet will 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. 

...

Info

...


The JobScheduler PowerShell CLI module is available for PowerShell jobs. A basic job using the PowerShell CLI might look like this:

...

Should execution policies not be explicitely explicitly ruled for a scheduling environment then we recommend to add Set-ExecutionPolicy bypass -scope process to the profile on a Windows platform.

Profile Handling

Display feature availability
StartingFromRelease1.11.5

...

  • Users who wish to suppress exit codes of failed executions of native Windows programs or scripts can use
    • $Global$script:LastExitCode = $null
  • This will disable the above mentioned check of the last exit code.

...

Jira
serverSOS JIRA
columnstype,key,issuelinks,fixversions,status,priority,summary,updated
maximumIssues20
jqlQuerylabels in (scripting-powershell)
serverId6dc67751-9d67-34cd-985b-194a8cdc9602