Scope
- JobScheduler offers Powershell as a language for implementation of Jobs
- Powershell Jobs have to been seen as the analogy for the Shell Jobs, even though there are some differences between Shell and Powershell Jobs
- 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 Master
Feature Availability
FEATURE AVAILABILITY STARTING FROM RELEASE 1.10.5
Powershell as a Shell
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 job.
Nevertheless, there are some compatibility issues described below.
Calling Order parameters or Job parameters
Example Shell: myscript.cmd %SCHEDULER_PARAM_NAME1% Example Powershell: myscript.cmd $env:SCHEDULER_PARAM_NAME1
Returning a parameter an its value to an Order
Example Shell: echo NAME1 = VALUE1 >> %SCHEDULER_RETURN_VALUES% Example Powershell: echo "NAME1 = VALUE1" >> $env:SCHEDULER_RETURN_VALUES%
Exit Code Handling
The following example throws no error in Shell but it breaks at line 2 and ends in an error for Powershell:
echo "job is starting" abcde echo "job is finishing"
The same example would be working in Powershell the following way:
echo "job is starting" try{abcde} catch{Break} echo "job is finishing"
This type of differences described above will be furhter supported like this from JobScheduler and seen as natural differences between the Shell and Powershell languages.
Examples
Example: Powershell as a Shell
Example 1: A simple job with some scripting analogue to basic Shell jobs might look like this:
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="/tests/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 function might look like this:
<?xml version="1.0" encoding="ISO-8859-1"?> <job process_class="/tests/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 "*" echo $files echo "job is finishing" </script> <run_time /> </job>
Example: Powershell API Jobs
An API Job (analogue to Javascript jobs)
<?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
Example 1:
Example: PowerShell Job with Debug output
Extras: CLI for Powershell Jobs