There are at least two different methods to pass parameters to a ps-script:
- as command line parameters
- as environment variables
As an example for both methods we will use a simple script which will list the content of a folder, filtered by a given filename extension. The parameters are defines in an order like this:
<order title="Executes the File PowerShell-Hallo.ps1"> <params> <param name="Script_Filename" value="$\{SCHEDULER_DATA\}\config\live\PowerShell\ListFilesByExtension.ps1"/> <param name="FolderName" value="c:\temp"/> <param name="FileNameExtension" value=".txt"/> </params> <run_time let_run="no"/> </order>
'FolderName' ist the name of the folder which has to be listed and 'FileNameExtension' is the value of the extension which will be selected.
The script code, without the initialisation of the parameters, is shown below:
$Dir = ..... $Ext = ..... $a = "List $Dir with Extension $Ext `n" + "=========================="; $a # Filenames as a list GCI $Dir -R | Where \{$_.Extension -EQ $Ext\} | sort-Object -descending Length | Format-List -property *
using command line parameters
powershell ... -file "%SCHEDULER_PARAM_SCRIPT_FILENAME%" "%SCHEDULER_PARAM_FolderName%" "%SCHEDULER_PARAM_FileNameExtension%"
$Dir = $args[0] $Ext = $args[1] . ...
Depending on the parameters the job has to be different. No general solution for a generic powershell job is possible.
using environment variables
The command line, which is used to start the script, has no parameters for the script:
powershell ... -file "%SCHEDULER_PARAM_SCRIPT_FILENAME%"
The scripts gets the values for the parameters by reading the environment variable for each parameter (see Passing Parameters to shell-jobs):
$Dir = $env:SCHEDULER_PARAM_FolderName $Ext = $env:SCHEDULER_PARAM_FileNameExtension . ...
see also: