Skip to content

Commit 4c0c4f1

Browse files
authored
some suggestions
1 parent a92885a commit 4c0c4f1

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed
Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
---
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:
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
66
ms.custom: sap:Desktop flows
7-
ms.date: 04/03/2025
8-
7+
ms.date: 04/15/2025
98
---
10-
# Issue while running the action 'Run PowerShell script'
9+
# "Failed to run PowerShell script" error when running the Run PowerShell script action
1110

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.
1312

1413
## Symptoms
1514

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.
1916

20-
The error message contains the following:
17+
The error message appears as follows:
2118

22-
```
19+
```output
2320
Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Failed to run PowerShell script. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
2421
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
2522
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
3027

3128
## Cause
3229

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.
3431

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:
3633

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.
3836

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.
4240
4341
## Resolution
4442

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`
4658

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.
4860

61+
1. Select **OK** to save changes and close all dialogs.

support/power-platform/power-automate/desktop-flows/media/take-screenshot-action-fails-in-unattended-mode/local security policy.png renamed to support/power-platform/power-automate/desktop-flows/media/take-screenshot-action-fails-in-unattended-mode/local-security-policy.png

File renamed without changes.
Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
---
22
title: Take screenshot action fails in unattended mode
33
description: Resolves an error that occurs in the action 'Take screenshot', when you run an unattended desktop flow in Microsoft Power Automate for desktop.
4-
ms.author: yiannismavridis
5-
ms.reviewer:
4+
ms.author: iomavrid
5+
author: yiannismavridis
66
ms.custom: sap:Desktop flows\Unattended flow runtime errors
7-
ms.date: 04/03/2025
8-
7+
ms.date: 04/15/2025
98
---
10-
# 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
1110

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.
1312

1413
## Symptoms
1514

16-
Using the **Take screenshot** action fails with error:
15+
The **Take screenshot** action fails with the following error message:
1716

18-
```
17+
```output
1918
Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Failed to take screenshot. ---> System.ComponentModel.Win32Exception: The handle is invalid
2019
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
2120
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize)
@@ -25,37 +24,34 @@ Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Faile
2524
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)
2625
```
2726

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-
3827
## Cause
3928

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.
4130

4231
## Resolution 1: Locate and allow binaries except for non-Windows ones to run without elevation prompt
4332

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":::
4536

4637
## Resolution 2: Change the registry key below
4738

48-
Hive: **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System**
39+
Modify the registry key to adjust the UAC behavior:
4940

50-
Key: **ConsentPromptBehaviorAdmin** DWORD, setting it to 5
41+
- Hive: **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System**
42+
- Registry key name: [ConsentPromptBehaviorAdmin](/windows/security/application-security/application-control/user-account-control/settings-and-configuration?tabs=reg#user-account-control-configuration)
43+
- Type: DWORD
44+
- Value: **5**
5145

52-
Options:
46+
Options for the **ConsentPromptBehaviorAdmin** key:
5347

5448
- **0** = Elevate without prompting
5549
- **1** = Prompt for credentials on the secure desktop
5650
- **2** = Prompt for consent on the secure desktop
5751
- **3** = Prompt for credentials
5852
- **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
6056

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)

support/power-platform/power-automate/toc.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@
154154
href: desktop-flows/troubleshoot-excel-errors.md
155155
- name: Errors when running attended or unattended desktop flows
156156
href: desktop-flows/troubleshoot-errors-running-attended-or-unattended-desktop-flows.md
157+
- name: '"Failed to run PowerShell script" error'
158+
href: desktop-flows/failed-to-run-powershell-script-error.md
159+
- name: '"Failed to take screenshot" error in unattended desktop flow run'
160+
href: desktop-flows/take-screenshot-action-fails-in-unattended-mode.md
157161
- name: Failed connection between Power Automate components
158162
href: desktop-flows/failed-connection-between-power-automate-components.md
159163
- name: Failed license check on a desktop flow run
@@ -164,8 +168,6 @@
164168
href: desktop-flows/invalid-credentials-errors-running-desktop-flows.md
165169
- name: Invalid credentials error using Microsoft Entra account
166170
href: desktop-flows/troubleshoot-ui-flow-invalid-credentials-error-using-aad-account.md
167-
- name: Issue while running the action 'Run PowerShell script'
168-
href: desktop-flows/issue-while-running-action-Run-PowerShell-script.md
169171
- name: '"Logon type not granted" error when creating connection or running desktop flow'
170172
href: desktop-flows/logon-type-has-not-been-granted.md
171173
- name: Machine registration failure
@@ -210,8 +212,6 @@
210212
href: desktop-flows/machine-not-shown-in-list.md
211213
- name: Unattended desktop flow fails with MSEntraMachineAlwaysPromptingForPassword
212214
href: desktop-flows/msentramachinealwayspromptingforpassword-error.md
213-
- name: Unattended desktop flow run fails with an error in the action 'Take screenshot'
214-
href: desktop-flows/take-screenshot-action-fails-in-unattended-mode.md
215215
- name: Flow creation
216216
items:
217217
- name: Can't find Excel Online table in Microsoft Flow

0 commit comments

Comments
 (0)