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
$Dir = $args[0] $Ext = $args[1] . ...
using environment variables
$Dir = $env:SCHEDULER_PARAM_FolderName $Ext = $env:SCHEDULER_PARAM_FileNameExtension . ...
see also: