Inline PowerShell Activity
Overviewβ
The Inline PowerShell (inline_powershell) Activity is a powerful feature for use in your automation packages. With this activity, you have the flexibility to execute PowerShell within your package without needing to create separate PowerShell Activities each time.
A good use of this is to perform smaller calculations, string manipulation and JSON / object manipulation for converting and transforming data between activities. Some examples of this will be shown further in this article.
A general rule of thumb for the Inline PowerShell Activity is to keep the lines of code to under (approximately) 100 lines before converting it into a full PowerShell Activity. Of course, this is not a hard limit, but will help you structure your package to make it more readable.
The Inline PowerShell Activity can be located by searching for "Inline PowerShell" in the list of activities in the package editor:
Here is a working example of the activity in a basic package. This example also demonstrates how you can pass information between the inline_powershell activities:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Test Package'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a test package'
option_category: 'Test Category'
steps:
- task: inline_powershell
alias: 'result1'
inputs:
script: |
return @{ a = 2; b = 3 };
- task: inline_powershell
alias: 'result2'
inputs:
numA: =result1.a
numB: =result1.b
script: |
return @{ result = [int]$numA * [int]$numB };
- task: chat_interaction
inputs:
text: =inline_powershell.result
Activity Behaviourβ
Using the Inline PowerShell Activity, you can execute PowerShell directly in your package execution.
The inputs for the Inline PowerShell activity work a bit differently to most activities, such that you can name the inputs whatever you like and they will be available / accessible via your PowerShell script. Examples of this are provided further below.
When the PowerShell is executed, it is run on a backend agent (called an "Activity Node") in your Pia tenant. This agent is for your exclusive use and is not shared with any other Pia tenants for security reasons.
Please note that PowerShell scripts which are run via Inline PowerShell are limited to a runtime of 10 minutes.
Input Propertiesβ
Use properties to modify the behaviour of the activity.
Property Name: <YOUR VARIABLE NAME HERE>
Property Description: You can create your own property names and reference them in your PowerShell script using the $VARIABLE_NAME syntax.
Here is an example demonstrating how dynamic input properties can be used:
- task: inline_powershell
inputs:
propertyA: 'A'
propertyB: 'B'
script: |
Write-Host "Hello World! Property A: $propertyA, Property B: $propertyB"
Property Name: script
Property Required: Yes
Property Description: This is the script for which the Inline PowerShell Activity will execute during package execution.
Output Propertiesβ
Output properties for this activity are dynamically defined by your PowerShell script.
Your script may not return any value, such as the example below. In this case, your script will have no accessible output properties:
- task: inline_powershell
inputs:
script: |
Write-Host "Hello World!"
The example below shows multiple output properties being returned from the activity (property_a and property_b):
- task: inline_powershell
inputs:
script: |
Write-Host "Hello World!"
return @{ property_a = "A"; property_b = "B"; }