Step-By-Step Guide to Use PowerShell Scripts to Subtract Two Integers

Let's consider an example of automating the task of subtracting two integers using Powershell scripts. We are going to write script for subtraction in the .ps1 file and use named parameters to call the function. To show how named parameters work, we are going to subtract first integer from second (integer2 - integer1) but the pass the parameters in reverse sequence (first integer1 and then integer2).

 

To automate subtraction of two numbers using Powershell scripts:

1.    Create a new process.

2.    From the Canvas Tools panel, add the Powershell Scripts activity to the Flowchart designer on the Canvas.

3.    In the Parameter bar, create In arguments, PowerShellScripts and Output of type String. These arguments are used to store the script and return value of the operation respectively.

4.    Create In arguments param1 and param 2 of type Int32. These arguments are used to store the values to subtract. We have assigned 4 to param1 and 3 to param2 here.

 

 

5.    In the Command Type list, select Scripts. The Cmdlet/Script list changes to Script

6.    In the Script list, select PowerShellScripts.

7.    Click the (Settings) icon. The Scripts Input dialog box appears. This allows you to call the function via named parameters.

 

 

8.    Click Add. In the Input Type list, select NamedParameter.

9.    In the Select Parameter list, select param1. Click Add again and add another parameter, param2.

10.  Click CONFIRM.

11.  Click Result Mapping link. The Output Path list appears. Select Output parameter to save the result of the substraction performed.

To view the output in Automation Studio, let's add a WriteLine activity. You can assign this process to a Robot, if you want to execute this process outside Automation Studio.

12.  Add a WriteLine activity below the Powershell Scripts activity.

13.  In the Text field, enter Output.

14.  Save the process.

15.  Setup the environment and then perform test run.

 

  

The console displays the difference of the two integers that is -1.

  Related Topics

Powershell Script