Skip to content

Commit c9a159f

Browse files
authored
Merge pull request #8648 from MicrosoftDocs/iomavrid-screenshot-and-powershell-issues-docs-update
AB#5351 & AB#5352: Iomavrid screenshot and powershell issues docs update
2 parents e10c171 + c366034 commit c9a159f

File tree

4 files changed

+126
-0
lines changed

4 files changed

+126
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
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+
ms.custom: sap:Desktop flows
7+
ms.date: 04/24/2025
8+
---
9+
# "Failed to run PowerShell script" error when running the Run PowerShell script action
10+
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.
12+
13+
## Symptoms
14+
15+
During the execution of a desktop flow in Power Automate for desktop, an error occurs when running the **Run PowerShell script** action. This issue might also occur after a recent Windows update.
16+
17+
The error message appears as follows:
18+
19+
```output
20+
Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Failed to run PowerShell script. ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
21+
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
22+
at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.SystemActions.RunPowershellScript(Variant powershellCode, Variant& scriptStandardOutput, Variant& scriptErrorOutput)
23+
--- End of inner exception stack trace ---
24+
at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.RunPowershellScript.Execute(ActionContext context)
25+
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)
26+
```
27+
28+
## Cause
29+
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 for the process. If the system fails to find `powershell.exe`, you might receive the error message.
31+
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 is the root cause, follow these steps:
33+
34+
1. Open a Command Prompt (CMD) window.
35+
1. Run `powershell.exe` by typing the command and pressing **Enter**.
36+
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.
40+
41+
## Resolution
42+
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, search for **Environment Variables**, and then 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, and then select **Edit**.
50+
51+
1. Add the directory path of `powershell.exe` to the list of paths.
52+
53+
In most cases, the missing path is **C:\WINDOWS\System32\WindowsPowerShell\v1.0\\**.
54+
55+
To confirm the correct path, open a PowerShell terminal and run the `$PsHome` command.
56+
57+
Use the displayed path as the value to add to the **Path** variable.
58+
59+
1. Select **OK** to save changes and close all dialogs.
Loading
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
title: Take Screenshot Action Fails in Unattended Mode
3+
description: Resolves an error that occurs in the Take screenshot action when you run an unattended desktop flow in Microsoft Power Automate for desktop.
4+
ms.author: iomavrid
5+
author: yiannismavridis
6+
ms.custom: sap:Desktop flows\Unattended flow runtime errors
7+
ms.date: 04/24/2025
8+
---
9+
# Unattended desktop flow run fails with the "Failed to take screenshot" error
10+
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.
12+
13+
## Symptoms
14+
15+
The **Take screenshot** action fails with the following error message:
16+
17+
```output
18+
Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Failed to take screenshot. ---> System.ComponentModel.Win32Exception: The handle is invalid
19+
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
20+
at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize)
21+
at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.SystemActions.TakeScreenShot(Variant fileName, Variant screenToCapture, Int32 screenCaptureOption, Boolean copyToClipboard, Int32 fileFormat)
22+
--- End of inner exception stack trace ---
23+
at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.TakeScreenshotBase.Execute(ActionContext context)
24+
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)
25+
```
26+
27+
## Cause
28+
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.
30+
31+
## Resolution 1: Locate and allow binaries except for non-Windows ones to run without elevation prompt
32+
33+
To solve this issue:
34+
35+
1. In Local Group Policy Editor, go to **Computer Configuration** > **Windows Settings** > **Security Settings** > **Local Policies** > **Security Options**.
36+
1. Locate the **User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode** security policy setting.
37+
1. Set the value to **Prompt for consent for non-Windows binaries**.
38+
39+
:::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":::
40+
41+
For more information about the best practices, location, values, policy management and security considerations for the security policy setting, see [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).
42+
43+
## Resolution 2: Change the registry key
44+
45+
Modify the registry key to adjust the UAC behavior:
46+
47+
- Hive: **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System**
48+
- Registry key name: [ConsentPromptBehaviorAdmin](/windows/security/application-security/application-control/user-account-control/settings-and-configuration?tabs=reg#user-account-control-configuration)
49+
- Type: DWORD
50+
- Value: **5**
51+
52+
Options for the **ConsentPromptBehaviorAdmin** key:
53+
54+
- **0** = Elevate without prompting
55+
- **1** = Prompt for credentials on the secure desktop
56+
- **2** = Prompt for consent on the secure desktop
57+
- **3** = Prompt for credentials
58+
- **4** = Prompt for consent
59+
- **5** (Default) = Prompt for consent for non-Windows binaries. Set the registry key to this value.
60+
61+
## More information
62+
63+
[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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@
160160
href: desktop-flows/troubleshoot-excel-errors.md
161161
- name: Errors when running attended or unattended desktop flows
162162
href: desktop-flows/troubleshoot-errors-running-attended-or-unattended-desktop-flows.md
163+
- name: '"Failed to run PowerShell script" error'
164+
href: desktop-flows/failed-to-run-powershell-script-error.md
165+
- name: '"Failed to take screenshot" error in unattended desktop flow run'
166+
href: desktop-flows/take-screenshot-action-fails-in-unattended-mode.md
163167
- name: Failed connection between Power Automate components
164168
href: desktop-flows/failed-connection-between-power-automate-components.md
165169
- name: Failed license check on a desktop flow run

0 commit comments

Comments
 (0)