cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rushirohit
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.

1 ACCEPTED SOLUTION

Accepted Solutions
thenecroscope1
Frequent Visitor

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

12 REPLIES 12
NikosMoutzou
Microsoft
Microsoft

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

createinput.PNG

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

Action.PNG

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

designer.PNG

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. 

 

input5.JPGinput6.JPG

 

 

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.

 

-Rushi

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.

 

Regards,

Rushi Rohit Kotha

thenecroscope1
Frequent Visitor

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

@thenecroscope1 

 

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:)

thenecroscope1
Frequent Visitor

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

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (2,766)