- 01 Aug 2024
- 3 Minutes to read
- Print
- DarkLight
Working with PowerShell Script Step Output
- Updated on 01 Aug 2024
- 3 Minutes to read
- Print
- DarkLight
Overview
When including a PowerShell Script step in a Flow in Decisions, the way the script operates greatly impacts 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 script's output 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's Raw Output and contains all 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. |
Running PowerShell Steps Remotely
PowerShell Script Steps can be Run Remotely by enabling the option "Run Remotely" from the properties panel.
winrm
enabled and set to listen to your IP. Refer to the article Run Powershell Remotely.Refer to and enter all the input details as per the following table,
Domain\User Name | Enter the IP_Address\username of the remote system |
Password | Password of the User |
Port Number | The port PowerShell runs on, by default, is set to 5985 |
Remote Computer Name | IP Address of the remote system |
Use SSL | If enabled, it will use a secure connection and thus need to change the Port Number to 5986. |
Enabling the Run Remotely option will expose another setting, Use Constant Credentials. Enter all the input details as per the following table to make use of constant credentials to connect to the PowerShell,
User Name | Enter the IP_Address\username of the remote system |
Password | Password of the User |
Port Number | The port PowerShell runs on, by default, it is set to 5985 |
Remote Computer Name | IP Address of the remote system |
Use SSL | If enabled, it will use a secure connection and thus need to change the Port Number to 5986 |