How to Integrate PowerShell with UiPath- Step by Step guide

Thanks for the tutorial buddy, but the only thing is that a comma is missing between the parameters, so it caused us a while to figure it out :sweat_smile:

So it should be like

[Parameter(Mandatory=$true)] [string]$ServiceState,
[Parameter(Mandatory=$true)] [string]$OutputFilePath

Apologies for that glitch… and thanks for bringing it to notice. I have now added a comment below the Image.
Hope the tutorial helped you overall :slight_smile:

1 Like

Hi @huston8,

This was a great tutorial!

I finally do not need to manipulate the strings passed into Invoke PowerShell activity rather use the method with parameters, a much elegant way to pass UiPath variables/arguments as you suggested.

Thank you. I am going to refer to this tutorial a lot in the forum answers!

1 Like

Hello @jeevith

Thank you very much for the acknowledgement, this made my day. It was a required for our use case couple of years back and so had to do some R&D. :slightly_smiling_face:

I am glad this is still useful till date.

(Just for info, I had also added another tutorial to run Powershell with admin privileges…Just in case anyone needs it)

Getting below erro, when I tried to invike power shell script
Invoke Power Shell: A command that prompts the user failed because the host program or the command type does not support user interaction. The host was attempting to request confirmation with the following message:

Please help.TeamsReports1.txt (13.1 KB)

attached is the .ps1 script

Let me know how to run this script using UiPath?


Can you tell me why the following does not work?


Hi @tsverthoff,

When you poll the command Get-Process in PowerShell, it is creating an object and not a string. So the casting fails as your output variable is set to string.

From documentation

By default, this cmdlet returns a process object that has detailed information about the process and supports methods that let you start and stop the process.

Reference : Get-Process (Microsoft.PowerShell.Management) - PowerShell | Microsoft Learn



I understand that get-process returns a process object, or a collection of process objects, but in a powershell console window, this will work:

ps c:\ $output = get-process winword,excel
ps c:\ echo $output

I assumed that since echo $output worked in a PS window it was simply trapping stdout, which is really what I want to do.

Is there a way to run a powershell command (from invoke powershell) and have the powershell stdout captured into a UIPath powershellvariable? I understand how to use the invoke powershell activity parameters, but I am baffled by the invoke powershell powershellvariables.

Hello Huston,
thank you very much.
If I have a script that is printing size of files in PS, how can I get this text as a String? I tried to get it from ‘Output’, but I get a generic object and not sure how to get the output text from it. Do you have any idea?

You may try to save the output of your PowerShell script in a text file and then read the text file (Read Text File activity) as a string and manipulate its data at your discretion. (25.8 KB)


THANK YOU VERY MUCH!!! it worked perfectly. :raised_hands: :trophy:

1 Like