...
There are at least two different methods approaches 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:
...
Depending on the parameters the every job has to be different. No general solution for a generic powershell job is possible. That will more or less increase the effort for maintenance of jobs.
In Addition, acessing at parameter by its position on the command line can lead into errors when anyone changes the commandline without change the script or the same script will be used by different jobs - with at the end - different command lines.
The better approach is to use the parameters bei its name.
using environment variables
...
Code Block |
---|
$Dir = $env:SCHEDULER_PARAM_FolderName $Ext = $env:SCHEDULER_PARAM_FileNameExtension . ... |
The advantage to use parameters by this method is that the access to the parameters is done by the Name of the parameter, not by the position of the value within the command line. Better: no parameter values on the command line are required.
see also:
- How to execute a PowerShell script with JS
- Setting the executionPolicy to execute .ps1-scripts
- How to get the Exit code of a powershell script
- A generic PowerShell Job
...