|
| 1 | +--- |
| 2 | +title: Issue while running the action 'Run PowerShell script' |
| 3 | +description: Resolves an error that occurs in the action 'Run PowerShell script', when you run a desktop flow in Microsoft Power Automate for desktop. |
| 4 | +ms.author: yiannismavridis |
| 5 | +ms.reviewer: |
| 6 | +ms.custom: sap:Desktop flows |
| 7 | +ms.date: 04/03/2025 |
| 8 | + |
| 9 | +--- |
| 10 | +# Issue while running the action 'Run PowerShell script' |
| 11 | + |
| 12 | +This article provides a resolution for an error that occurs in the action 'Run PowerShell script', when you run a desktop flow in Microsoft Power Automate for desktop. |
| 13 | + |
| 14 | +## Symptoms |
| 15 | + |
| 16 | +During a flow run, an error occurs while running the action 'Run PowerShell script'. This can also occur due to a Windows update. |
| 17 | + |
| 18 | +## Detection |
| 19 | + |
| 20 | +The error message contains the following: |
| 21 | + |
| 22 | +``` |
| 23 | +Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Failed to run PowerShell script. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified |
| 24 | + at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) |
| 25 | + at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.SystemActions.RunPowershellScript(Variant powershellCode, Variant& scriptStandardOutput, Variant& scriptErrorOutput) |
| 26 | + --- End of inner exception stack trace --- |
| 27 | + at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.RunPowershellScript.Execute(ActionContext context) |
| 28 | + at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments) |
| 29 | +``` |
| 30 | + |
| 31 | +## Cause |
| 32 | + |
| 33 | +The `Run Powershell script` action internally starts an instance of `powershell.exe` while also providing the specified script of the action's input as an argument to the process. |
| 34 | + |
| 35 | +If the system is not able to find `powershell.exe`, it will throw the mentioned runtime error to the user. |
| 36 | + |
| 37 | +The most probable cause for this is the PATH environment variable not including the folder of the `powershell.exe` executable. |
| 38 | + |
| 39 | +To ensure that this is the cause for this problem, users can launch a Command Prompt (CMD) window and try to launch `powershell.exe` from there. If the message |
| 40 | +`'powershell.exe' is not recognized as an internal or external command, operable program or batch file.` |
| 41 | +is shown as a result, this is the root cause of the error. |
| 42 | + |
| 43 | +## Resolution |
| 44 | + |
| 45 | +Edit the `PATH` environment variable and add the missing path, the folder of the executable `powershell.exe`. |
| 46 | + |
| 47 | +On most occasions, the missing path will be `"C:\WINDOWS\System32\WindowsPowerShell\v1.0\"` but to get the actual path, you could launch a PowerShell terminal and run `$PsHome`. |
| 48 | + |
0 commit comments