- 12 Jul 2021
- 2 Minutes to read
- Print
- DarkLight
Working with PowerShell Script Step Output
- Updated on 12 Jul 2021
- 2 Minutes to read
- Print
- DarkLight
Overview
When including a PowerShell Script step to a Flow in Decisions, the way that the script operates has a large impact on how to handle its output and what path the Flow takes after that step.
Scripts that Output PowerShell Objects
Some PowerShell Scripts return lists of PowerShell objects from which Decisions can select the properties a user desires. An example of this is the below script. The sample script can be imported into Decisions.
The step retrieves a list of processes running on the Decisions server and the script definition tells Decisions to select the ID and Process Name properties from the objects that the script returns. Each of these properties appears in the Outputs area of the step as an array of values. The PowerShell Module Basics provides details on this sample script.
Scripts that Output Text
Other PowerShell scripts can return results as text. A simple example of this is the following PowerShell Script:
$Variable = "This is an example of string output."
Return $Variable
Because this PowerShell script does not return an object with properties, there are no properties for Decisions to select and therefore no need to specify anything in the Outputs area of the script. When this PowerShell Script is added as a Flow step, users can access the output of the script in the Edit Input Mappings using the Script Raw Output, a single text string containing all of the lines of output that the script generated.
Non-terminating Errors
Some commands in PowerShell scripts do not halt script execution when they encounter a problem. They write error messages to a special error stream instead. This output can be mapped from a PowerShell Script step using the Non-terminating Errors output of the step. This is a separate output stream from the Script Raw Output and contains all of the errors that any portion of the script wrote. An example script that writes to this output stream is:
$Error_Message = "This is a non-terminating error"
Write-Error $Error_Message
Return
PowerShell Script Step Paths
Because PowerShell scripts can run to completion but still generate error messages, Decisions provides multiple paths out of a PowerShell Script Step:
Path | Taken When |
---|---|
Done | PowerShell script ran successfully |
Done With Errors | PowerShell script completed, and errors were written to the Non-terminating Errors property. |
Failed | PowerShell script encountered an error that halted its execution. Instead of any normal output or non-terminating errors, an Exception Details property is provided. |
Both the Done With Errors and Failed paths can be hidden using the Hide Done With Errors Path and Hide Failed Path checkboxes. If the Done With Errors path is hidden, the Done path will be taken instead and the Non-terminating Errors property will contain any errors. If the Failed path is hidden, then the Done path will be taken instead and the Exception Details information is placed in the Script Raw Output property.