Versions Compared

Key

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

...

Additional examples are available from the PowerShell CLI - Use Cases article.

...

Parameter Handling

Reading Order parameters or Job parameters

PowerShell jobs offer additional methods for reading parameters:

Code Block
# Example PowerShell solution 1: environment variable for task/order parameter
$env:SCHEDULER_PARAM_NAME1
 
# Example PowerShell solution 2: shorthand notation for task/order parameter
$spooler_params.get( "name1" )
$spooler_params.value( "name1" )

# Example PowerShell solution 3 - read all task/order parameters as Variable_set
$variableSet = $spooler_params.getAll()

 

PowerShell jobs can be considered as a migration path for shell jobs. This suggests that any shell job can possibly be converted (with a few changes) to a PowerShell job. 

Please consider compatibility issues as explained below.

Reading Order parameters or Job parameters

Reading parameters works slightly different for PowerShell jobs than for shell jobs, using $env:VARIABLE for PowerShell instead of %VARIABLE% as for shell:

Code Block
# Example Shell: environment variable for task/order parameter
myscript.cmd %SCHEDULER_PARAM_NAME1%

# Example PowerShell solution 1:4 environment- variableread forall task/order parameters as parameter
myscript.cmd $env:SCHEDULER_PARAM_NAME1object
$parameters = $spooler_params.items
$parameters.name1 
 
# Example PowerShell solution 25: shorthand notation foraccess task/order parameter
# Example PowerShell solution 2.1
myscript.cmd $spooler_task.params().getvalue( "name1" )

# Example PowerShell solution 2.2
myscript.cmd $spooler_params 6: access order parameter
$spooler_task.order().params().value( "name1" )

# Example PowerShell solution 2.3
myscript.cmd $spooler_params.items.name1 
 
# Example PowerShell solution 2.4 - read all task/order parameters as Variable_set
$variableSet = $spooler_params.getAll()
# Example PowerShell solution 2.5 - read all task/order 

Explanations

  • Parameter passing by environment variables is only available for PowerShell jobs that do not implement any of the API functions spooler_init(), spooler_exit(), spooler_process() etc.
    • Solution 1
      • $env:SCHEDULER_PARAM_NAME1 returns the respective parameter
  • A new object $spooler_params has been introduced 
    • The objects includes parameters from both job and order. For parameters with the same name an order parameter beats a job parameter.
    • The object includes the following methods:
      • Solution 2
        • $spooler_params.get( "name1" ) reads a parameter value
        • $spooler_params.value( "name1" ) is an alias for $spooler_params.get()
      • Solution 3
        • $spooler_params.getAll() returns a Variable_set with all job and order parameters.
      • Solution 4
        • $parameters = $spooler_params.items returns a PSObject that allows to access individual parameters as PowerShell properties
        • $parameters.name1 returns the parameter "name1" as property
  • The  usual API methods for parameters access are available:
    • Solution 5
      • $spooler_task.params().value( "name1" ) reads a job parameter

    • Solution 6
      • $spooler_task.order().params().value( "name1" ) reads an order parameter

Returning a parameter and its value to an Order or Job

 

Code Block
# Example PowerShell solution 1: set task/order parameter 
$spooler_params.set( "name1", "value2" )
 
# Example PowerShell solution 2: setting a task parameter 
$spooler_task.params().set_value( "name1", "value2" )

# Example PowerShell solution 3: setting an order parameter
$spooler_task.order().params().set_value( "name1", "value2" )

Explanations

  • Parameters are return
    • Solution 1
      • $spooler_params.set( "name1", "value2" ) 
        • sets a job parameter if the current job is configured as a standalone job
        • sets an order parameter if the current job is configured for a job chain.
    • Solution 2
      • $spooler_task.params().set_value( "name1", "value2" ) sets a parameter for a job (for instance parameter name1 with the initial value value1) and modifies the value to value2
    • Solution 3
      • $spooler_task.order().params().set_value( "name1", "value2" ) sets a parameter for an order (for instance parameter name1 with the initial value value1) and modifies the value to value2

Anchor
powershell-as-a-shell
powershell-as-a-shell
Compatibility between PowerShell and Shell

PowerShell jobs can be considered as a migration path for shell jobs. This suggests that any shell job can possibly be converted (with a few changes) to a PowerShell job. 

Please consider compatibility issues as explained below.

Reading Order parameters or Job parameters

Reading parameters works slightly different for PowerShell jobs than for shell jobs, using $env:VARIABLE for PowerShell instead of %VARIABLE% as for shell:

Code Block
# Example Shell: environment variable for task/order parameter
myscript.cmd %SCHEDULER_PARAM_NAME1%
parameters as object
$parametes = $spooler_params.items
 
# Example PowerShell solution 31: accessenvironment variable for task/order parameter
myscript.cmd $spooler_task.params().value( "name1" )
$env:SCHEDULER_PARAM_NAME1
 
# Example PowerShell solution 42: shorthand notation accessfor task/order parameter
myscript.cmd $spooler_taskparams.orderget( "name1" )
myscript.cmd $spooler_params().value( "name1" )

Returning a parameter and its value to an Order

...