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
Copy file name to clipboardExpand all lines: articles/logic-apps/add-run-powershell-scripts.md
+89-86Lines changed: 89 additions & 86 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,32 +64,30 @@ This guide shows how to add the action in your workflow and add the PowerShell c
64
64
65
65
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.
66
66
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.
68
68
69
69
- To return the script's results or other data to your workflow, see [Return data to your workflow](#return-data-to-workflow).
70
70
71
-
1. To review the workflow output in Application Insights, see [View output in Application Insights](#log-output-application-insights).
72
-
73
71
The following example shows the action's **Parameters** tab with the sample script code:
74
72
75
73
:::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":::
76
74
77
75
The following example shows the sample script code:
78
76
79
77
```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.
# 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"
91
89
92
-
# Use Push-WorkflowOutput to push outputs forward to subsequent actions
90
+
# Use Push-WorkflowOutput to push outputs into subsequent actions.
93
91
Push-WorkflowOutput -Output $customResponse
94
92
```
95
93
@@ -98,30 +96,61 @@ This guide shows how to add the action in your workflow and add the PowerShell c
98
96
```powershell
99
97
$action = Get-TriggerOutput
100
98
$results = "Hello from PowerShell!"
101
-
Push-ActionOutputs -body $results
99
+
Push-WorkflowOutput -Output $results
102
100
```
103
101
104
102
1. When you finish, save your workflow.
105
103
106
-
<aname="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).
107
105
108
-
## View the script file
106
+
<aname="access-trigger-action-outputs"></a>
109
107
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
111
109
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:
113
111
114
-
1. On the **Advanced Tools** page, select **Go**, which opens the **KuduPlus** console.
$populatedString = "Send the $statusCode for the trigger status and $actionOutputName."
115
118
116
-
1. Open the **Debug console** menu, and select **CMD**.
119
+
Push-WorkflowOutput -Output $populatedString
120
+
```
117
121
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()**.
119
126
120
-
1. Go to your workflow's folder, which contains the .ps1 file, along this path: **site/wwwroot/{workflow-name}**
127
+
### Parameters
121
128
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
+
<aname="return-data-to-workflow"></a>
123
146
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:
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.
159
188
160
189
> [!NOTE]
161
190
>
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).
|**Output**| Varies. | The output that you want to return to the workflow. This output can have any type. |
177
207
|**Clobber**| Varies. | An optional switch parameter that you can use to override the previously pushed output. |
178
208
179
-
<aname="access-trigger-action-outputs"></a>
209
+
## Authenticate and authorize access with a managed identity using PowerShell
180
210
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.
182
212
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.
$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:
191
216
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).
194
218
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:
199
220
200
-
### Parameters
221
+
- On the **Role** tab, a **Contributor** role is usually sufficient.
201
222
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**.
217
224
218
-
<aname="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.
219
226
220
-
## Return outputs to your workflow
227
+
1. In your **Execute PowerShell Code** action, include the following code as the first statement:
221
228
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
+
<aname="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.
223
252
224
253
<aname="log-output-application-insights"></a>
225
254
@@ -320,32 +349,6 @@ MyLogicApp
320
349
- requirements.psd1
321
350
```
322
351
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
-
349
352
## Compilation errors
350
353
351
354
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
354
357
355
358
### A workflow action doesn't return any output.
356
359
357
-
Make sure that you use **Push-WorkflowOutput**.
360
+
Make sure that you use the **Push-WorkflowOutput** cmdlet.
358
361
359
362
### Execute PowerShell Code action fails: "The term '{some-text}' is not recognized..."
0 commit comments