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 / How can I execute a Po...
Power Automate
Unanswered

How can I execute a PowerShell script within a Power Virtual Agent for a workflow that has been created in Power Automate?

(0) ShareShare
ReportReport
Posted on by 16

Hi All

I have created a Power Automate Desktop flow using a recorder on the server which works as follows:

Open the PowerShell as admin
run a script line and then exit from Powershell.


I am able to record these steps successfully in Power Automate Desktop. It executes successfully when run manually, but when I connect the same flow to the Power Virtual Agent chatbot and try to run the flow only a few steps are performed, that is PowerShell opens in admin mode. Still, the script line won't get typed on the Powershell command prompt.

I have recorded these by opening both Powershell and Power Automate Desktop in Admin mode still, but I cannot solve the issue.

 

As we are using Trail Version of Power Virtual Agent is that could be reason are we not getting this recording option.


Can anyone help me with the solution?



Thanks In Advance

Categories:
I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hi @SwathiKindre 

     

    Would it be issue with power automate desktop while typing the commands?

    Any error shown while running the flow ?

     

    Also there won't be any other issue with respect to power virtual agents as bot is able to run when triggered via power virtual agents.

     

    For running powershelll scripts, i would recommend to try Run PowerShell script action in power automate desktop as shown below

    Nived_Nambiar_0-1692889742539.png

     

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • SwathiKindre Profile Picture
    16 on at

    Hi

    Flow needed : Open windows powershell as Admin and type a command line that gives access permission for a folder over the network, Type the command on Powershell and run it.
    The command that we pass is -->  net share Foldername /DELETE

    to create a flow for the above given flow, I have used a recorder in Power automate whose steps are given below:

    1. Use the Windows shortcut to open Powershell as an admin

    2. typing the command line given above

    3. Run the command and exit from Powershell

     

    I have created this flow power automate flow and attached it to a PVA.

     

    when I try to run this flow from PVA the second step explained is not running, which is the PowerShell application opens as powershell admin but the script line won't get typed, I mean send keys won't work.


    Can you help me with this!

  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hi @SwathiKindre 

     

     

    Have you tried using actions which i have suggested to run powershell script, that would be quite faster 🙂

     

     

  • SwathiKindre Profile Picture
    16 on at

    Hi 

     

    Yes, I have tried using that but I have not got the desired output.

    If we use that action will that open the PowerShell in admin mode and run the command line??

  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hi @SwathiKindre 

     

    Give a try with this 

    https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Run-PowerShell-admin-and-execute-a-command-one-liner/td-p/850200

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • SwathiKindre Profile Picture
    16 on at

    Hi

     

    In the above solution link, you have given they have passed the credentials, but the location where i am trying to run this powershell is on a server that has already admin rights to it, if we just click on open powershell as admin it opens directly without asking for any credentials.

     

    Is there any other alternative options?

    As it is running on a server with which is an admin itself but when opening an application we need to select it to open as admin and then run a command.

    SwathiKindre_0-1693142808036.png

    this is how my flow looks,and the 10th step is not working ,even when both power automate desktop and powershell are running as admin

     

  • Verified answer
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    Hi @SwathiKindre 

     

    Since you are sending keys to foreground window, it is not sure that always powershell will be in foreground (if other windows are opened) so it may/may not work. So try with other options instead of foreground window in send keys 

    Nived_Nambiar_1-1693147523220.png

     

    OR 

     

    Also to run the powershell command with admin privilage,

    could you try this command from powershell (using Run Powershell script action)

     

    $command = "Your-Command-Here"
    Start-Process -FilePath "powershell" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$command`"" -Verb RunAs

     

     

    pass the command you want to run instead of Your-Command-Here.

     

    Let me know if it works for you 🙂

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

  • SwathiKindre Profile Picture
    16 on at

    Thank You @Nived_Nambiar 
    This solution worked.👍

  • Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    You are welcome @SwathiKindre !!

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

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