Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Invoke PowerShell script using Power Automate Desktop

Hi, I have an existing flow where it fetches data from email and save it to a csv file with header. I have created another flow in Power Automate Desktop version to run a PowerShell script. I have added UI flow to my existing flow with input variable but script is unable to identify the input parameters. Could you please suggest next steps.


Accepted Solutions
Helper I
Helper I

Or as alternative approach, after a bit of trial an error this worked for me 🙂


$env:MyVar = '%PowershellOutput%';C:\Scripts\scripts2.ps1


View solution in original post


Hello, rushirohit!


Initially, you should create the respective Input parameters in the Power Automate Desktop Designer (more info here). The Input parameters included in the already existing Flow should be created also in Power Automate Desktop.


After that, you could check whether the Powershell script is being executed successfully in the Designer using the Input's default value.


I hope the above helps.

Hello @NikosMoutzou,


Yes, I have created input variables in Power Automate Desktop App. Below pictures for reference.


input variable.JPGinput2.JPG









We do not have any default value for input. Below is the screenshot from my existing flow and output of the step when flow runs.

Hello again rushirohit.


Unfortunately, the screenshot from your existing flow is not displayed. I would recommend using a default value for your Input parameter in order to check during Debugging if the Parameter's value is being taken into account in the PowerShell execution.


For example, I have followed the below steps:

1. Create the Input parameter in Designer using a default value


2. Create the Poweshell Action and use the specific Parameter in my Powershell code


3. The Input parameter is used in the execution as it could be observed from the Powershell Output parameter.


Hi @NikosMoutzou,


Yes, if we provide a single PowerShell command it works. When I am trying to run .ps1 or .bat file it does not take the input.

I did save "Write-Host $SSO" in a sample script and tried to run the script. 





Hi rushirohit.


In order to use a Parameter as a dynamic value in a PowerShell script, the actual PowerShell code has to be inserted in the 'PowerShell code to run' field of the 'Run PowerShell script' Action. When a user inserts the file path of a PowerShell script file, the script will be executed successfully but the Parameter will not be handled as a Variable(dynamic) but as text (static).


I hope this helps.

Hello @NikosMoutzou ,


Could you please suggest how I can add multiple commands into a single action because we have commands to connect to different services and a function with 10 lines of code and then actual command to run.



Hi @rushirohit 


I suggest that you manually store the commands into a text file. Then, using the "Read text from file" action, the whole text can be saved into a variable.


This variable can be entered as an input to the "Run PowerShell script" action.


I hope the above helps!

Hi @PetrosF-MSFT,


I did try the suggested solution it's not successful. I have created a ticket with MS, but it's not helpful. Could you please suggest next POA.



Rushi Rohit Kotha

Helper I
Helper I

Or as alternative approach, after a bit of trial an error this worked for me 🙂


$env:MyVar = '%PowershellOutput%';C:\Scripts\scripts2.ps1




Hi, I have run into a similar issue but where I can't run my PowerShell script as "admin". Running through script on it's own works but when I run it with Desktop Flow I get access denied and have no other way of forcing it to run as an admin. 


I found this thread interesting. Were you able to get it to run a locally saved script and still write back the output to your flow? How did you go about it?


Thanks in advance:)

Helper I
Helper I

I didn't really have any issues with Admin mode. Saying that though, I only tried a basic example. The only thing that may help, I'm not sure if this will work, is to change the UAC settings on your system, which may always force the Powershell session to always run in Admin mode. Not ideal I know.


In the end I abandon this approach as I had issues with being granted access to the gateway service within the company I worked for. So to get around it, I used Azure DevOps, stored my PS scripts with in Azure DevOps Git and installed an agent on the server. I'm not sure on the cost implications yet though


Good luck


Not sure if that helps, but just a thought



Yeah I tried that, I temporarily disabled all UAC and made PowerShell ISE (all 4 versions) run as admin by default. I also made Power Automate Desktop App run as admin by default and to top it off, I'm a local administrator and no luck.


I can run an AD script fine if I launch ISE as an admin but when it runs using w/e framework Flow uses, it runs as a mortal user and there's NO way to force it to run as admin so I'm out of luck I guess. 


Thanks nonetheless! 

Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Top Kudoed Authors
Users online (4,561)