Versions Compared

Key

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

...

Code Block
# Example Shell: 
echo NAME1 = VALUE1 >> %SCHEDULER_RETURN_VALUES%

# Example PowerShell: 
echo "NAME1 = VALUE1" >> $env:SCHEDULER_RETURN_VALUES%VALUES
$spooler_task.order.params.set_value( 'NAME1', 'VALUE1')

Exit Code Handling

The following example throws no error in a Shell job but it breaks at line 2 and ends in an error for a PowerShell job:

...

Code Block
linenumberstrue
echo "job is starting"
try { abcde }
catch {Break}
echo "job is finishing"

...

Code Block
<?xml version="1.0" encoding="ISO-8859-1"?>
<job process_class="my_Agent">
    <script language="powershell">
	function spooler_process()
		{
		$spooler_log.info("job is starting")
		$files = get-childitem dir *
		echo $files 
		$spooler_log.info("job is finishing")
		return $false
		}
	
    </script>
    <run_time />
</job>

...

This PowerShell job contains a prejob with a  pre-processing job Monitor script (API job) which that is executed before the main job script (the shell job) is executed:

Code Block
<?xml version="1.0" encoding="ISO-8859-1"?>

<job  process_class="my_Agent">
    <script  language="powershell">

echo "job is starting"
sleep 10
echo "job is finishing"

    </script>
    <monitor  name="process_powershell" ordering="0">
        <script  language="powershell">
            <![CDATA[
		function spooler_process_before()
		{
		$files = get-childitem *
		echo $files
		$spooler_log.info("hallo")
		return $true			# check for a "go" file that is required to start the job
			$rc = (Test-Path -Path "/tmp/go.txt" -PathType Leaf)
			echo ".. looking up go file: $rc"
			return $rc
		}
            ]]>
        </script>
    </monitor>
    <run_time />
</job>

Example: PowerShell Job with

...

different outputs

The following job shows how to set different outputs for PowerShell such as:

...

  1. The standard PowerShell verbose setting is considered for jobs
  2. The example shows how to set this at lines 11-12

...

  1. The standard PowerShell debug setting is ignored for jobs
  2. Instead, the current log level of the job is applied, e.g. log level "debug1" will log debug messages
  3. The example shows how to set this at lines 16-17

...

...

 

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 jobsoutput:
$VerbosePreference = "continue"
Write-Verbose "job: this is some verbose output"

# Standard PowerShell debug setting:
$DebugPreference is ignored for jobs:= "continue"
# In Insteadaddition the current log level of the job is applied, e.g. log level "debug1" logs debug messages
$DebugPreference = "continue"
Write-Debug "job: this is some debug output"

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

# This 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 debug setting is ignored for jobs ($DebugPreference = "Continue")
    • Instead, the current log level of the job is applied, e.g. log level "debug1" 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.

 

Extras: PowerShell CLI for Powershell Jobs

...