Versions Compared

Key

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

...

  • JobScheduler offers PowerShell as a language for implementation of Jobsjobs.
  • The introduction of PowerShell as a language for JobScheduler has not only with API jobs to do, but can also be used a language for Shell shell jobs.
  • There are some differences between Shell and PowerShell Jobs that will be supported as they are (see PowerShell as a Shell).
  • The decision to include PowerShell as a language for JobScheduler (among others) is in the same line with the development of Microsoft programming languages.
  • PowerShell Jobs can only be run on Agents and not on the jobs are executed with Agents, not with a Master

Feature Availability

...

Example 1: A simple PowerShell job with some scripting analogue similar to basic Shell shell jobs might look like this:

...

Example 2: A basic PowerShell job including a the call of to a function might look like this:

...

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()
		{
			# 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>

Explanations

  • The monitor script is executed before a task is started for this job.
  • Its purpose is to decide if the task should be started or not. This decision is taken from the existence of the file /tmp/go.txt.
  • The return code reflects the decision to start or not to start a task for the job.

Example: PowerShell Job with different outputs

...

Info
  • The feature is only available in case your Agent is running on a machine with PowerShell available
  • For more information about how to set use the PowerShell CLI modules on your Agent, have a look at PowerShell Command Line Interface - Introduction

 

Anchor
powershell-as-a-shell
powershell-as-a-shell

...

Compatibility between PowerShell and Shell

As mentioned before, Powershell PowerShell Jobs should be seen as the analogy for Shell Jobs in the futurea migration path for shell jobs. That means, every Shell shell job should possibly be able to be converted (with any or a few changes) converted into to a PowerShell job. 

Nevertheless, there are some Please consider compatibility issues as described explained below.

Calling Order parameters or Job parameters

Calling parameters works differently for PowerShell jobs than for Shell shell jobs, using $env: for PowerShell instead of % as for Shellshell:

Code Block
# Example Shell: 
myscript.cmd %SCHEDULER_PARAM_NAME1%

# Example PowerShell: 
myscript.cmd $env:SCHEDULER_PARAM_NAME1

Returning a parameter

...

and its value to an Order

Setting a parameter in an order (for instance parameter name1 with the initial value value1) and modifying the value to value2 and returning the parameter to the order so that the next job chain node uses the new value. For PowerShell this only works using the API methods for $spooler_task.order():

Code Block
# Example Shell: 
echo name1 = value2 >> %SCHEDULER_RETURN_VALUES%

# Example PowerShell: 
$spooler_task.order().params().set_value("name1","value2")

 

...