Table of Contents |
---|
Scope
- JobScheduler offers Powershell PowerShell as a language for implementation of Jobs
- Powershell PowerShell Jobs have to been seen as the analogy for the Shell Jobs, even though there are some differences between Shell and Powershell JobsPowerShell Jobs (see PowerShell as a Shell)
- The decision to include Powershell PowerShell as a language for JobScheduler (among others) is in the same line with the development of Microsoft programming languages
- Powershell PowerShell Jobs can only be run on Agents and not on the Master
...
Display feature availability | ||
---|---|---|
|
...
Anchor | ||||
---|---|---|---|---|
|
As mentioned before, Powershell Jobs should be seen as the analogy for Shell Jobs in the future. That means, every Shell job should be able to be (with any or few changes) converted into a Powershell PowerShell job.
Nevertheless, there are some compatibility issues as described below.
Calling Order parameters or Job parameters
Code Block |
---|
# Example Shell: myscript.cmd %SCHEDULER_PARAM_NAME1% # Example PowershellPowerShell: myscript.cmd $env:SCHEDULER_PARAM_NAME1 |
Returning a parameter an its value to an Order
Code Block |
---|
# Example Shell: echo NAME1 = VALUE1 >> %SCHEDULER_RETURN_VALUES% # Example PowershellPowerShell: echo "NAME1 = VALUE1" >> $env:SCHEDULER_RETURN_VALUES% |
...
The following example throws no error in a Shell job but it breaks at line 2 and ends in an error for Powershella PowerShell job:
Code Block | ||
---|---|---|
| ||
echo "job is starting" abcde echo "job is finishing" |
The same example would be working in Powershell PowerShell the following way:
Code Block | ||
---|---|---|
| ||
echo "job is starting" try{abcde} catch{Break} echo "job is finishing" |
Note |
---|
This type of differences described above will be furhter further supported like this from JobScheduler and seen as natural differences between the Shell and Powershell PowerShell languages. |
Examples
Example:
...
PowerShell as a Shell
Example 1: A simple PowerShell job with some scripting analogue to basic Shell jobs 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 $files = dir * echo $files echo "job is finishing" </script> <run_time /> </job> |
Example 2: A basic PowerShell job including that calls a call of a function might look like this:
Code Block |
---|
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="my_Agent"> <script language="powershell"> function get_files($directory){ echo "entering function get_files" return get-childitem $directory } echo "job is starting" sleep 10 $files = get_files "*my_directory" echo $files echo "job is finishing" </script> <run_time /> </job> |
Example:
...
PowerShell API Jobs
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="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> |
Info |
---|
For further information about how to write API Jobs in PowerShell, have a look at http://www.sos-berlin.com/doc/en/scheduler.doc/api/api-powershell.xml. You will find the available methods as well as some useful examples for your API jobs. |
Example: Combination of both (
...
PowerShell Job with
...
Monitor as a Pre-Processing job)
This PowerShell job contains a pre-processing job (API job) which is executed before the main script (the shell job) is executed:
...
The integration of the PowerShell CLI into PowerShell jobs is also available as well. A basic job using the PowerShell CLI might look like this:
...