Versions Compared

Key

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

...

 

Code Block
linenumberstrue
<?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[
# Standard PowerShell verbose setting is considered for log output:
$VerbosePreference = "continue"
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 is appliedhas to be set, e.g. log level "debug1" logs debug messages
Write-Debug "job: this is some debug output"

# creates a warning in the log
Write-Warning "job: this is a warning"

# can be used to throw an error
# Write-Error "job: this is an error"

# This does not work: Use of Write-Host is not allowed
# Write-Host "job: this is some output"
        ]]>
    </script>

    <run_time />
</job>

Explanations

  1. Setting PowerShell verbosity for a job
    • The standard PowerShell verbosity setting is considered for log output
    • Use $VerbosePreference = "Continue" followed by the Write-Verbose cmdlet.
  2. Setting PowerShell debug messages for a job
    • The standard PowerShell The Standard PowerShell debug setting is ignored considered for jobs log output in jobs (through $DebugPreference = "Continue")
    • InsteadIn addition, the current log level of the job is appliedhas to be set, e.g. log level "debug1" will  will log debug messages
    • With the JobScheduler log level being switched to info no debug output is written to the log file
    • With the JobScheduler log level being switched to debug1debug2, ..., debug9 then debug output is added to the log.
    • The example shows how to set this at lines 16-17
  3. Setting Warning Messages can be done as in line 19
  4. Setting Error Messages can be done as in line 22
    • This throws an error and ends effectively the job with an error 
  5. Write-Host does not work for PowerShell jobs as such jobs are not running in a PowerShell host console, but in a PowerShell run-time process.

 

...