cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SwathiKindre
Frequent Visitor

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

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

1 ACCEPTED SOLUTION

Accepted Solutions

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! 🙌

View solution in original post

9 REPLIES 9

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! 🙌

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!

Hi @SwathiKindre 

 

 

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

 

 

SwathiKindre
Frequent Visitor

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??

Hi @SwathiKindre 

 

Give a try with this 

https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Run-PowerShell-admin-and-execute-a-comman...

 

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! 🙌

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

 

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
Frequent Visitor

Thank You @Nived_Nambiar 
This solution worked.👍

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! 🙌

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,972)