Versions Compared

Key

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

...

Example: Powershell API Jobs

An A basic API Job (, analogue to Javascript jobs for instance, might look like this:

Code Block
<?xml version="1.0" encoding="ISO-8859-1"?>
<job  process_class="/tests/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>

Example: Combination of

...

both (Shell Job with Monitors as a Pre-Processing job)

This job contains a pre-processing job (API job) which is executed before the main script (the shell job) is executedExample 1:

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

<job  process_class="/tests/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()
		{
		$env:files = get-childitem *
		echo $files
		$spooler_log.info("hallo")
		return $false
		}
            ]]>
        </script>
    </monitor>
    <run_time />
</job>

Example: PowerShell Job with Debug output

 

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


<job  process_class="Agent01" stop_on_error="no">
    <settings >
        <log_level ><![CDATA[debug1]]></log_level>
    </settings>

    <script  language="powershell">
        <![CDATA[
# Standard PowerShell verbose setting is considered for jobs:
$VerbosePreference = "continue"
Write-Verbose "job: this is some verbose output"

# 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" logs debug messages
Write-Debug "job: this is some debug output"

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>

 

Extras: CLI for Powershell Jobs

The integration of the PowerShell CLI into PowerShell jobs is also available. A basic job using the PowerShell CLI might look like this:

Code Block
collapsetrue
 <job process_class="my_process_class">
 <script language="powershell">
 <![CDATA[

Import-Module JobScheduler
use-master myjobscheduler:4444
getshow-status

 ]]>
 </script>
<run_time />
Info

 The feature is only available in case you are running your Jobs on