Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


ErikC
  •  ErikC
  • Free support Topic Starter
2016-01-13T09:16:16Z
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
  1. Open the PowerShell task, and click on the 'Parameters' button;
  2. click on the Add button to add a line in the grid;
  3. in the Name column, put the parameter name. Be sure not using spaces and don't start with a $;
  4. in the Value column, add the value of the parameter, this can also be a Visualcron variable:
  5. click on the OK button to save your parameter.
For this example I created two parameters:
Name: Param1
Value: 1st value

Name: Param2
Value: 4

2nd 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:
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 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.
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:
1st value1
5

That's it folks!
Happy programming.
Erik
Uses Visualcron since 2006.
Sponsor
Forum information
Scroll to Top