cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bouillons
Helper V
Helper V

How to run powershell from a powerapp

The easiest way to allow many many many scenarios imho would be to do this as follows:

 

  • Allow the launch command to point to a powershell file to execute it
  • Provide a configuration on the app or tenant settings that toggles "enable local machine access" (default off), to enable this to work or not
  • The powershell file runs in the context of the logged on user on the local machine
  • the powershell can return information to the app
  • the launch command has a true/false parameter to wait for the powershell execution to complete or not

This would enable a gazillion scenarios where you might want to create a local file, print, or run any type of script by clicking a button in the power app that today people are trying to find workarounds for via Flow and on premise gateways etc...

 

I have seen examples of Launch to open a web page, to dial a phone number, to send an email, etc... so a lot of the plumbing is already there.

7 REPLIES 7
rimatos
Community Support
Community Support

Hi @bouillons

 

Currently there is no connector for PowerShell available to be used in either Flow or PowerApps. as such, there is no direct way to tap into this directly.

 

with this in mind there are only 2 possibilites that come into my mind that could be used as a workaround for this issue.

 

  1. Create a Custom Connector

 

This option would require you to create a custom connector that would tap directly into PowerShell API, although I'm not exactly sure how this could be accomplished.

Information on creating  custom connectors is available here.

 

      2. Use a UI Flow for Desktop.

 

In this option you would need to create a UI Flow for desktop. This would tap into some of your points provided such as:

  • Launching Powershell Script
  • Run in context of logged user
  • Return information to app

 

You can use UI flows to automate repetitive tasks in Windows and Web applications. UI flows records and plays back user interface actions (clicks, keyboard input, etc.) for applications that don't have easy-to-use or complete APIs available.

 

To achieve these points and return back the results, you would need to incorporate the UI Flows action into a Flow which could be acceded through PowerApps.

 

 

Hope this helps!

 

Regards,

Ricardo 

 


 

The problem with these workarounds is that it is my understanding that they run in the infrastructure of the flow platform. What I need is to run this on the machine that launched the power app. How would this work with a UI flow ? Which UI does this control ? Does it control actions that normally the user would take himself on his local machine ? Under which user does this run ?

Hi @bouillons 

 

When you create a UI Flow, one of the prerequisites you have is to first set up a on-premises gateway for the device where the UI Flow will be triggered. This is due to the fact that the UI flow will need to have access to the local machine to execute the actions that you want to automate for the user.

 

When you create this UI Flow you will need to use the same account for setting up the gateway, and to use as credential in the UI Flow connection, When doing this you are assuring that the UI flow is being executed as the user you have set up here.

 

You have some additional documentation here for executing unattended and attended UI Flows, that might help clear some of these questions: https://docs.microsoft.com/en-us/power-automate/ui-flows/run-ui-flow.

 

Let me know if this helps!

 

 

Regards,

Ricardo

 

 

I tried to record a UI Flow to perform the following action

 

"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE" "c:\temp\Ticket-18.xml" /mFilePrintDefault /mFileExit /q /n

 

Basically, what I want is to open a file in word, print it out and close word

 

When testing it always fails, because the recorder just starts word and then sits there waiting. It doesn't open the file, but stays stuck on the Word Home page:

 

The action in Flow generated by the recorder is just to start Word. If I try to add command line parameters it even fails to start Word at all

 

Capture.JPG

 

Hi @bouillons 

When you recorded the steps or your UI flow did you verify if the steps all appeared in the actions? When you say print out your intent is to print the file?

When you execute the Flow make sure that you are running it as attended, otherwise you will need to be logged out of the machine where the flow will execute in order for it to function.

Additionally, you can also try and contact Microsoft Support through https://admin.powerplatform.microsoft.com/support in order to troubleshoot this in more depth.

 

 

Regards,

Ricardo

Max44
Helper V
Helper V

Save-Module -Name Microsoft.PowerApps.Administration.PowerShell -Path
Import-Module -Name Microsoft.PowerApps.Administration.PowerShell
Save-Module -Name Microsoft.PowerApps.PowerShell -Path
Import-Module -Name Microsoft.PowerApps.PowerShell

axorth
Frequent Visitor

All of these options seem way over complicated. Why not just setup an Azure Automation account and use the "Create Job" step to execute it?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,865)