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:
Name:
Param1Value:
1st valueName:
Param2Value:
42nd step - Declare the parameters in codeNow 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:
Param(
[string] $Param1,
[int] $Param2
)
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 variableNow 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.
Param(
[string] $Param1,
[int] $Param2
)
$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!
Happy programming.
Erik
Edited by user
2018-09-20T13:01:45Z
|
Reason: Extra info for param value
Uses Visualcron since 2006.