How to use Parameters in the PowerShell task - VisualCron - Forum

Community forum

Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
Offline ErikC  
#1 Posted : Wednesday, January 13, 2016 10:16:16 AM(UTC)

Rank: Paid support

Joined: 2/26/2008(UTC)
Posts: 1,520
Location: Amsterdam

Thanks: 114 times
Was thanked: 220 time(s) in 188 post(s)
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:
	[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.
	[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

That's it folks!
Happy programming.

Edited by user Thursday, September 20, 2018 3:01:45 PM(UTC)  | Reason: Extra info for param value

Uses Visualcron since 2006.
thanks 5 users thanked ErikC for this useful post.
Support on 1/14/2016(UTC), Support on 1/14/2016(UTC), bbusse on 4/1/2016(UTC), Jason Schaitel (Neu) on 2/17/2017(UTC), Gary_W on 6/8/2018(UTC)
Users browsing this topic
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Scroll to Top