If you want to use parameters in a PowerShell task you can add them in your PowerShell task.
However, you have to add some code in the PowerShell task to make them work.1st step - Add the parameters in the parameter section
- Open the PowerShell task, and click on the 'Parameters' button;
- click on the Add button to add a line in the grid;
- in the Name column, put the parameter name. Be sure not using spaces and don't start with a $;
- in the Value column, add the value of the parameter, this can also be a Visualcron variable:
- click on the OK button to save your parameter.
For this example I created two parameters:
Value: 1st value
Value: 42nd step - Declare the parameters in code
Now that you have created the parameters, in the PowerShell code you need to declare them first before you can use them.
This is done at the top of your code:
You need to tell the type and name of your parameters. Use the same names from step 1, but starting the names this time with the $.
The parameter order is not an issue.3rd step - Use the parameters as a variable
Now in your PowerShell code you can use the parameters as variables. Use the names from step 2, so your parameter name with a $ in front.
$Param1 + 1
$Param2 + 1
The code above will give you the output of Param1 with a '1' added to it, as you add something to a string.
Param2 is an integer, so the '1' will in this case add one to the Param2 value, which contains 4.
The output will be:
That's it folks!
Edited by user
| Reason: Extra info for param value
Uses Visualcron since 2006.