You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
2
+
title: Failed To Run PowerShell Script Error
3
+
description: Solves an error that occurs when you run the Run PowerShell script action in a desktop flow in Microsoft Power Automate for desktop.
4
+
ms.author: iomavrid
5
+
author: yiannismavridis
6
6
ms.custom: sap:Desktop flows
7
-
ms.date: 04/03/2025
8
-
7
+
ms.date: 04/15/2025
9
8
---
10
-
# Issue while running the action 'Run PowerShell script'
9
+
# "Failed to run PowerShell script" error when running the Run PowerShell script action
11
10
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.
11
+
This article provides a resolution for an error that occurs when running the [Run PowerShell script](/power-automate/desktop-flows/actions-reference/scripting#runpowershellscript) action in Microsoft Power Automate for desktop.
13
12
14
13
## Symptoms
15
14
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
15
+
During the execution of a desktop flow in Power Automate for desktop, an error occurs message when running the **Run PowerShell script** action. This issue might also occur after a recent Windows update.
19
16
20
-
The error message contains the following:
17
+
The error message appears as follows:
21
18
22
-
```
19
+
```output
23
20
Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Failed to run PowerShell script. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
24
21
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
25
22
at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.SystemActions.RunPowershellScript(Variant powershellCode, Variant& scriptStandardOutput, Variant& scriptErrorOutput)
@@ -30,19 +27,35 @@ Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Failed to run PowerShell
30
27
31
28
## Cause
32
29
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.
30
+
The **Run PowerShell script** action internally starts an instance of `powershell.exe`and provides the script specified in the action's input as an argument to the process. If the system fails to find `powershell.exe`, you might receive the error message.
34
31
35
-
If the system is not able to find `powershell.exe`, it will throw the mentioned runtime error to the user.
32
+
The most likely cause of this issue is that the **Path** environment variable doesn't include the directory containing the `powershell.exe` executable. To confirm this as the root cause, follow these steps:
36
33
37
-
The most probable cause for this is the PATH environment variable not including the folder of the `powershell.exe` executable.
34
+
1. Open a Command Prompt (CMD) window.
35
+
1. Run `powershell.exe` by typing the command and pressing Enter.
38
36
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.
37
+
If the following message occurs, then the issue lies in the missing path to `powershell.exe`in the **Path** environment variable.
38
+
39
+
> 'powershell.exe' is not recognized as an internal or external command, operable program or batch file.
42
40
43
41
## Resolution
44
42
45
-
Edit the `PATH` environment variable and add the missing path, the folder of the executable `powershell.exe`.
43
+
To resolve this issue, follow these steps to update the **Path** environment variable to include the directory of the `powershell.exe` executable:
44
+
45
+
1. Open the Start menu and search for "Environment Variables." Select **Edit the system environment variables**.
46
+
47
+
1. In the **System Properties** window, select **Environment Variables**.
48
+
49
+
1. Under the **System variables** section, locate and select the **Path** variable, then select **Edit**.
50
+
51
+
1. Add the directory path of `powershell.exe` to the list of paths. In most cases, the missing path is:
52
+
53
+
**C:\WINDOWS\System32\WindowsPowerShell\v1.0\\**
54
+
55
+
1. To confirm the correct path, open a PowerShell terminal and run the following command:
56
+
57
+
`$PsHome`
46
58
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`.
59
+
Use the displayed path as the value to add to the **Path** variable if it differs.
48
60
61
+
1. Select **OK** to save changes and close all dialogs.
title: Take screenshot action fails in unattended mode
3
3
description: Resolves an error that occurs in the action 'Take screenshot', when you run an unattended desktop flow in Microsoft Power Automate for desktop.
# Unattended desktop flow run fails with an error in the action 'Take screenshot'
9
+
# Unattended desktop flow run fails with the "Failed to take screenshot" error
11
10
12
-
This article provides a resolution for an error that occurs in the action 'Take screenshot', when you run an unattended desktop flow in Microsoft Power Automate for desktop.
11
+
This article provides a resolution for an error that occurs in the [Take screenshot](/power-automate/desktop-flows/actions-reference/workstation#takescreenshotbase) action when running an unattended desktop flow in Microsoft Power Automate for desktop.
13
12
14
13
## Symptoms
15
14
16
-
Using the **Take screenshot** action fails with error:
15
+
The **Take screenshot** action fails with the following error message:
17
16
18
-
```
17
+
```output
19
18
Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Failed to take screenshot. ---> System.ComponentModel.Win32Exception: The handle is invalid
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)
26
25
```
27
26
28
-
### Applies to
29
-
- All versions
30
-
31
-
### Modes
32
-
- Unattended
33
-
34
-
## Detection
35
-
36
-
While using the **Take screenshot** action, the above error is thrown when a specific security policy is in place.
37
-
38
27
## Cause
39
28
40
-
The security policy refers to the way a UAC window (for admin privileges) is prompted and does not allow the flow to retrieve the screen and capture the screenshot.
29
+
The issue occurs due to a specific security policy that impacts how a User Account Control (UAC) window (for administrative privileges) is prompted. This policy prevents the flow from accessing the screen and capturing the screenshot.
41
30
42
31
## Resolution 1: Locate and allow binaries except for non-Windows ones to run without elevation prompt
43
32
44
-
:::image type="content" source="media/take-screenshot-action-fails-in-unattended-mode/local security policy.png" alt-text="Screenshot of the local security policies window":::
33
+
Configure the [User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode](/previous-versions/windows/it-pro/windows-10/security/threat-protection/security-policy-settings/user-account-control-behavior-of-the-elevation-prompt-for-administrators-in-admin-approval-mode) security policy setting.
34
+
35
+
:::image type="content" source="media/take-screenshot-action-fails-in-unattended-mode/local-security-policy.png" alt-text="Screenshot of the User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode setting in the Local Security Policy window." lightbox="media/take-screenshot-action-fails-in-unattended-mode/local-security-policy.png":::
Options for the **ConsentPromptBehaviorAdmin** key:
53
47
54
48
-**0** = Elevate without prompting
55
49
-**1** = Prompt for credentials on the secure desktop
56
50
-**2** = Prompt for consent on the secure desktop
57
51
-**3** = Prompt for credentials
58
52
-**4** = Prompt for consent
59
-
-**5** = Prompt for consent for non-Windows binaries (default) <- Set option to this
53
+
-**5** (Default) = Prompt for consent for non-Windows binaries. Set the registry key to this value.
54
+
55
+
## More information
60
56
61
-
You can read more about this setting [here](https://learn.microsoft.com/windows/security/application-security/application-control/user-account-control/settings-and-configuration).
57
+
[User Account Control settings and configuration](/windows/security/application-security/application-control/user-account-control/settings-and-configuration)
0 commit comments