How to Integrate PowerShell with UiPath
This topic is a step by step guide for integrating Powershell with Uipath. There is an ‘Invoke Powershell Activity’ available in Uipath which can be used to run the powershell scripts.
For our example purpose, let us consider a simple powershell script which gives us the status of windows services on the machine. This script will have two input parameters:
• ServiceState (String) – To get the status of service. For e.g. ‘Running’ , ‘Stopped’ etc
• OutputFilePath – The path of file where the output of script will be saved.
Follow the steps below to run the powershell script via Uipath.
Save the Powershell script file in the text format. For e.g. If you have a powershell file with name ‘GetService.ps1’. open the file with notepad and save it as ‘GetService.txt’.
Identify the parameters used in the Powershell script. For e.g. ServiceState and OutputFilePath as shown in example below.
In Uipath, use the ‘Read Text File’ activity in your flowchart. Provide the ‘File name’ as the full file path of the Powershell file ‘GetService.txt’ which is saved in text format earlier. Save the output ‘content’ of the Read text file activity into a variable, for. E.g. ‘PSScript’ as shown below.
Add ‘Invoke Power Shell’ activity into your flowchart after the ‘Read Text File’. In the command field enter the variable name ‘PSScript’ i.e. the content of text file read earlier.
In the properties of ‘Invoke Power Shell’ , check the option of ‘IsScript’.
Click on Parameters and enter the parameters for scripts identified earlier. (Parameters value can be passed through variables. In our example, we have passed the values directly)
Save the Uipath workflow and Run the flowchart.
After the flowchart runs successfully, navigate to the Output folder path and check if the output file is generated as shown below:
Example uploaded for reference:
PowershellExample.zip (13.2 KB)