web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Invoke PowerShell scri...
Power Automate
Unanswered

Invoke PowerShell script using Power Automate Desktop

(1) ShareShare
ReportReport
Posted on by 20

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.

I have the same question (0)
  • NikosMoutzou Profile Picture
    Microsoft Employee on at

    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.

  • rushirohit Profile Picture
    20 on at

    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.

  • NikosMoutzou Profile Picture
    Microsoft Employee on at

    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

  • rushirohit Profile Picture
    20 on at

    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

     

     

  • NikosMoutzou Profile Picture
    Microsoft Employee on at

    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.

  • rushirohit Profile Picture
    20 on at

    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

  • PetrosF-MSFT Profile Picture
    on at

    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!

  • rushirohit Profile Picture
    20 on at

    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

  • Verified answer
    thenecroscope1 Profile Picture
    48 on at

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

     

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

     

  • Community Power Platform Member Profile Picture
    on at

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard