Run PowerShell script Action(Power Automate Desktop)

08/22/2023

Japanese version.

This Action that executes arbitrary PowerShell.

This is effective for processing that would be difficult to handle with actions alone, but because it involves entering the program code itself, it is recommended that it be used only minimally in environments used by non-systems engineers.

However, complex conditional expressions are too large to be built with actions, so there are cases where code is more appropriate.

How to use

Drag "Run PowerShell script" from "Scripting" under "Actions".

Set parameters.

Parameter

PowerShell code to run

Specifies the PowerShell code to execute.

Power Automate Desktop variables are available in this (enclose the variable name in %).

The basic form is then to output the result with Write-Output() and receive it in the Variables produced PowerShellOutput.

Code example.

In this example, the result is the Power Automate Desktop variable (NewVar) plus 5.

It is possible to read the value of a Power Automate Desktop variable.
However, it is not possible to set the value in reverse (a runtime error will occur).

Variables produced as a result.

Variables produced

Stores the result of executing "PowerShell code to run".

PowershellOutput

The results of PowerShell execution and standard output are stored.

The standard output is set when the code is specified as follows.

Write-Output content

This can be used to return calculation results to flow.

Code example.
Variables produced as a result.

ScriptError

PowerShell error output (Write-Error), runtime errors, and syntax errors are set.

Write-Error(content);
Code example.

In addition to the specified contents, runtime and syntax errors will be added.

Execution result of the code example.

For those who want to learn Power Automate Desktop effectively


The information on this site is now available in an easy-to-read e-book format.

Or Kindle Unlimited (unlimited reading).

You willl discover how to about basic operations.

By the end of this book, you will be equipped with the knowledge you need to use Power Automate Desktop to streamline your workflow.

Links

Scripting Actions

Examples of Use

How to crop an image.