Skip to content

Commit afe0b23

Browse files
author
ecfan
committed
Reorganize sections
1 parent aa4d268 commit afe0b23

File tree

1 file changed

+89
-86
lines changed

1 file changed

+89
-86
lines changed

articles/logic-apps/add-run-powershell-scripts.md

Lines changed: 89 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,30 @@ This guide shows how to add the action in your workflow and add the PowerShell c
6464

6565
1. After the action information pane opens, on the **Parameters** tab, in the **Code File** box, update the prepopluated sample code with your own code.
6666

67-
- To access data coming from your workflow, see [Access trigger outputs, preceding action outputs, and your workflow](#access-trigger-action-outputs) later in this guide.
67+
- To access data coming from your workflow, see [Access workflow trigger and action outputs in your script](#access-trigger-action-outputs) later in this guide.
6868

6969
- To return the script's results or other data to your workflow, see [Return data to your workflow](#return-data-to-workflow).
7070

71-
1. To review the workflow output in Application Insights, see [View output in Application Insights](#log-output-application-insights).
72-
7371
The following example shows the action's **Parameters** tab with the sample script code:
7472

7573
:::image type="content" source="media/add-run-powershell-scripts/action-sample-script.png" alt-text="Screenshot shows Azure portal, Standard workflow designer, Request trigger, Execute PowerShell Code action with information pane open, and Response action. Information pane shows sample PowerShell script." lightbox="media/add-run-powershell-scripts/action-sample-script.png":::
7674

7775
The following example shows the sample script code:
7876

7977
```powershell
80-
# Use these cmdlets to retrieve outputs from prior steps
81-
# oldActionOutput = Get-ActionOutput -ActionName <name of old action>
82-
# oldTriggerOutput = Get-TriggerOutput
78+
# Use the following cmdlets to retrieve outputs from prior steps.
79+
# $triggerOutput = Get-TriggerOutput
80+
# $ActionOutput = Get-ActionOutput -ActionName <action-name>
8381
8482
$customResponse = [PSCustomObject]@{
8583
Message = "Hello world!"
8684
}
8785
88-
# Use Write-Host/ Write-Output/Write-Debug to log messages to application insights
89-
# Write-Host/Write-Output/Write-Debug and 'returns' will not return an output to the workflow
90-
# Write-Host "Sending to application insight logs"
86+
# Use Write-Debug/Write-Host/Write-Output/ to log messages to Application Insights.
87+
# Write-Host/Write-Output/Write-Debug and 'return' won't return an output to the workflow.
88+
# Write-Host "Sending to Application Insight logs"
9189
92-
# Use Push-WorkflowOutput to push outputs forward to subsequent actions
90+
# Use Push-WorkflowOutput to push outputs into subsequent actions.
9391
Push-WorkflowOutput -Output $customResponse
9492
```
9593

@@ -98,30 +96,61 @@ This guide shows how to add the action in your workflow and add the PowerShell c
9896
```powershell
9997
$action = Get-TriggerOutput
10098
$results = "Hello from PowerShell!"
101-
Push-ActionOutputs -body $results
99+
Push-WorkflowOutput -Output $results
102100
```
103101

104102
1. When you finish, save your workflow.
105103

106-
<a name="view-script-file"></a>
104+
After you run your workflow, you can review the workflow output in Application Insights, if enabled. For more information, see [View output in Application Insights](#log-output-application-insights).
107105

108-
## View the script file
106+
<a name="access-trigger-action-outputs"></a>
109107

110-
1. In the [Azure portal](https://portal.azure.com), open your Standard logic app resource that has the workflow you want.
108+
## Access workflow trigger and action outputs in your script
111109

112-
1. On the logic app resource menu, under **Development Tools**, select **Advanced Tools**.
110+
The output values from the trigger and preceding actions are returned using a custom object, which have multiple parameters. To access these outputs and make sure that you return the value that you want, use the [**Get-TriggerOutput**](#get-triggeroutput), [**Get-ActionOutput**](#get-actionoutput), and [**Push-WorkflowOutput**](#push-workflowoutput) cmdlets plus any appropriate parameters described in the following table, for example:
113111

114-
1. On the **Advanced Tools** page, select **Go**, which opens the **KuduPlus** console.
112+
```powershell
113+
$trigger = Get-TriggerOutput
114+
$statusCode = $trigger.status.ToString();
115+
$action = Get-ActionOutput -ActionName Compose
116+
$actionOutput = $action.outputs['actionOutput'].ToString();
117+
$populatedString = "Send the $statusCode for the trigger status and $actionOutputName."
115118
116-
1. Open the **Debug console** menu, and select **CMD**.
119+
Push-WorkflowOutput -Output $populatedString
120+
```
117121

118-
1. Go to your logic app's root location: **site/wwwroot**
122+
> [!NOTE]
123+
>
124+
> In PowerShell, if you reference an object that has **JValue** type inside a complex object, and you
125+
> add that object to a string, you get a format exception. To avoid this error, use **ToString()**.
119126
120-
1. Go to your workflow's folder, which contains the .ps1 file, along this path: **site/wwwroot/{workflow-name}**
127+
### Parameters
121128

122-
1. Next to the file name, select **Edit** to open and view the file.
129+
| Parameter | Type | Description |
130+
|-----------|------|-------------|
131+
| **Name** | String | The name for the trigger or action. |
132+
| **Inputs** | JToken | The input values passed into the trigger or action. |
133+
| **Outputs** | JToken | The outputs from the executed trigger or action. |
134+
| **StartTime** | DateTime | The start time for the trigger or action. |
135+
| **EndTime** | DateTime | The end time for the trigger or action. |
136+
| **ScheduledTime** | DateTime | The scheduled time to run the trigger or action or trigger. |
137+
| **OriginHistoryName** | String | The origin history name for triggers with the **Split-On** option enabled. |
138+
| **SourceHistoryName** | String | The source history name for a resubmitted trigger. |
139+
| **TrackingId** | String | The operation tracking ID. |
140+
| **Code** | String | The status code for the result. |
141+
| **Status** | String | The run status for the trigger or action, for example, **Succeeded** or **Failed**. |
142+
| **Error** | JToken | The HTTP error code. |
143+
| **TrackedProperties** | JToken | Any tracked properties that you set up. |
144+
145+
<a name="return-data-to-workflow"></a>
123146

124-
## Custom PowerShell commandlets
147+
## Return outputs to your workflow
148+
149+
To return any outputs to your workflow, you must use the [**Push-WorkflowOutput** cmdlet](#push-workflowoutput).
150+
151+
## Custom PowerShell commands
152+
153+
The **Execute PowerShell Code** action includes following custom [PowerShell commands (cmdlets)](/powershell/scripting/powershell-commands) for interacting with your workflow and other operations in your workflow:
125154

126155
### Get-TriggerOutput
127156

@@ -155,13 +184,14 @@ Get-ActionOutput [ -ActionName <String> ]
155184

156185
### Push-WorkflowOutput
157186

158-
Pushes output from the **Execute PowerShell Code** action to your workflow, which can pass back any object type. If the return value is null, you get a null object error from the commandlet.
187+
Pushes output from the **Execute PowerShell Code** action to your workflow, which can pass back any object type. If the return value is null, you get a null object error from the cmdlet.
159188

160189
> [!NOTE]
161190
>
162-
> The **Write-Host**, **Write-Debug**, and **Write-Output** commandlets don't return values to your workflow.
163-
> The **return** statement also doesn't return values to your workflow. However, you can use these commandlets
164-
> to write trace messages that appear in Application Insights.
191+
> The **Write-Debug**, **Write-Host**, and **Write-Output** cmdlets don't return values
192+
> to your workflow. The **return** statement also doesn't return values to your workflow.
193+
> However, you can use these cmdlets to write trace messages that appear in Application Insights.
194+
> For more information, see [Microsoft.PowerShell.Utility](/powershell/module/microsoft.powershell.utility).
165195
166196
#### Syntax
167197

@@ -176,50 +206,49 @@ Push-WorkflowOutput [-Output <Object>] [-Clobber]
176206
| **Output** | Varies. | The output that you want to return to the workflow. This output can have any type. |
177207
| **Clobber** | Varies. | An optional switch parameter that you can use to override the previously pushed output. |
178208

179-
<a name="access-trigger-action-outputs"></a>
209+
## Authenticate and authorize access with a managed identity using PowerShell
180210

181-
## Access workflow trigger and action outputs in your script
211+
With a [managed identity](/entra/identity/managed-identities-azure-resources/overview), your logic app resource and workflow can authenticate and authorize access to any Azure service and resource that supports Microsoft Entra authentication without including credentials in your code.
182212

183-
The output values from the trigger and preceding actions are returned using a custom object, which have multiple parameters. To access these outputs and make sure that you return the value that you want, use the [**Get-TriggerOutput**](#get-triggeroutput), [**Get-ActionOutput**](#get-actionoutput), and [**Push-WorkflowOutput**](#push-workflowoutput) commandlets plus any appropriate parameters described in the following table, for example:
213+
From inside the **Execute PowerShell Code** action, you can authenticate and authorize access with a managed identity so that you can perform actions on other Azure resources where you enabled access. For example, you can restart a virtual machine or get the run details of another logic app workflow.
184214

185-
```powershell
186-
$trigger = Get-TriggerOutput
187-
$statusCode = $trigger.status.ToString();
188-
$action = Get-ActionOutput -ActionName Compose
189-
$actionOutput = $action.outputs['actionOutput'].ToString();
190-
$populatedString = "Send the $statusCode for the trigger status and $actionOutputName."
215+
To use the managed identity from inside the **Execute PowerShell Code** action, you must follow these steps:
191216

192-
Push-WorkflowOutput -Output $populatedString
193-
```
217+
1. [Follow these steps to set up the managed identity on your logic app and grant the managed identity access on the target Azure resource](authenticate-with-managed-identity.md?tabs=standard).
194218

195-
> [!NOTE]
196-
>
197-
> In PowerShell, if you reference an object that has **JValue** type inside a complex object, and you
198-
> add that object to a string, you get a format exception. To avoid this error, use **ToString()**.
219+
On the target Azure resource, review the following considerations:
199220

200-
### Parameters
221+
- On the **Role** tab, a **Contributor** role is usually sufficient.
201222

202-
| Parameter | Type | Description |
203-
|-----------|------|-------------|
204-
| **Name** | String | The name for the trigger or action. |
205-
| **Inputs** | JToken | The input values passed into the trigger or action. |
206-
| **Outputs** | JToken | The outputs from the executed trigger or action. |
207-
| **StartTime** | DateTime | The start time for the trigger or action. |
208-
| **EndTime** | DateTime | The end time for the trigger or action. |
209-
| **ScheduledTime** | DateTime | The scheduled time to run the trigger or action or trigger. |
210-
| **OriginHistoryName** | String | The origin history name for triggers with the **Split-On** option enabled. |
211-
| **SourceHistoryName** | String | The source history name for a resubmitted trigger. |
212-
| **TrackingId** | String | The operation tracking ID. |
213-
| **Code** | String | The status code for the result. |
214-
| **Status** | String | The run status for the trigger or action, for example, **Succeeded** or **Failed**. |
215-
| **Error** | JToken | The HTTP error code. |
216-
| **TrackedProperties** | JToken | Any tracked properties that you set up. |
223+
- On the **Add role assignment** page, on the **Members** tab, for the **Assign access to** property, make sure that you select **Managed identity**.
217224

218-
<a name="return-data-to-workflow"></a>
225+
- After you select **Select members**, on the **Select managed identities** pane, select the managed identity that you want to use.
219226

220-
## Return outputs to your workflow
227+
1. In your **Execute PowerShell Code** action, include the following code as the first statement:
221228

222-
To return any outputs to your workflow, you must use the [**Push-WorkflowOutput** commandlet](#push-workflowoutput).
229+
```powershell
230+
Connect-AzAccount -Identity
231+
```
232+
233+
1. Now, you can work with the Azure resource using cmdlets and modules.
234+
235+
<a name="view-script-file"></a>
236+
237+
## View the script file
238+
239+
1. In the [Azure portal](https://portal.azure.com), open your Standard logic app resource that has the workflow you want.
240+
241+
1. On the logic app resource menu, under **Development Tools**, select **Advanced Tools**.
242+
243+
1. On the **Advanced Tools** page, select **Go**, which opens the **KuduPlus** console.
244+
245+
1. Open the **Debug console** menu, and select **CMD**.
246+
247+
1. Go to your logic app's root location: **site/wwwroot**
248+
249+
1. Go to your workflow's folder, which contains the .ps1 file, along this path: **site/wwwroot/{workflow-name}**
250+
251+
1. Next to the file name, select **Edit** to open and view the file.
223252

224253
<a name="log-output-application-insights"></a>
225254

@@ -320,32 +349,6 @@ MyLogicApp
320349
- requirements.psd1
321350
```
322351

323-
## Authenticate and authorize access with a managed identity using PowerShell
324-
325-
With a [managed identity](/entra/identity/managed-identities-azure-resources/overview), your logic app resource and workflow can authenticate and authorize access to any Azure service and resource that supports Microsoft Entra authentication without including credentials in your code.
326-
327-
From inside the **Execute PowerShell Code** action, you can authenticate and authorize access with a managed identity so that you can perform actions on other Azure resources where you enabled access. For example, you can restart a virtual machine or get the run details of another logic app workflow.
328-
329-
To use the managed identity from inside the **Execute PowerShell Code** action, you must follow these steps:
330-
331-
1. [Follow these steps to set up the managed identity on your logic app and grant the managed identity access on the target Azure resource](authenticate-with-managed-identity.md?tabs=standard).
332-
333-
On the target Azure resource, review the following considerations:
334-
335-
- On the **Role** tab, a **Contributor** role is usually sufficient.
336-
337-
- On the **Add role assignment** page, on the **Members** tab, for the **Assign access to** property, make sure that you select **Managed identity**.
338-
339-
- After you select **Select members**, on the **Select managed identities** pane, select the managed identity that you want to use.
340-
341-
1. In your **Execute PowerShell Code** action, include the following code as the first statement:
342-
343-
```powershell
344-
Connect-AzAccount -Identity
345-
```
346-
347-
1. Now, you can use the modules and commandlets that you want to work with the Azure resource.
348-
349352
## Compilation errors
350353

351354
In this release, the web-based editor includes limited IntelliSense support, which is still under improvement. Any compilation errors are detected when you save your workflow, and the Azure Logic Apps runtime compiles your script. These errors appear in your logic app's error logs.
@@ -354,7 +357,7 @@ In this release, the web-based editor includes limited IntelliSense support, whi
354357

355358
### A workflow action doesn't return any output.
356359

357-
Make sure that you use **Push-WorkflowOutput**.
360+
Make sure that you use the **Push-WorkflowOutput** cmdlet.
358361

359362
### Execute PowerShell Code action fails: "The term '{some-text}' is not recognized..."
360363

0 commit comments

Comments
 (0)