Working with PowerShell Script Step Output
  • 01 Aug 2024
  • 3 Minutes to read
  • Dark
    Light

Working with PowerShell Script Step Output

  • Dark
    Light

Article summary

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.

   Powershell-Sample-Scripts.zip  

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
The script above does not return any objects or any Raw Script Output. If a Flow step is created using it, its Non-terminating Errors property will contain the error message text when the Flow is run. Because more than one error message can be written, Decisions provides the Non-terminating Errors as an array of strings.

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:

PathTaken When
DonePowerShell script ran successfully
Done With ErrorsPowerShell script completed, and errors were written to the Non-terminating Errors property.
FailedPowerShell script encountered an error that halted its execution. Instead of any normal output or non-terminating errors, an Exception Details property is provided.

Note:
Both the Done With Errors and Failed paths can be hidden using the Hide Done With Errors Path and Hide Failed Path checkboxes under the properties panel on the right.

Running PowerShell Steps Remotely

PowerShell Script Steps can be Run Remotely by enabling the option "Run Remotely" from the properties panel.

Note:
Ensure to have the necessary permissions to run the steps remotely, and ensure that the remote machine has 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 NameEnter the IP_Address\username of the remote system
PasswordPassword of the User
Port NumberThe port PowerShell runs on, by default, is set to 5985
Remote Computer NameIP Address of the remote system
Use SSLIf 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 NameEnter the IP_Address\username of the remote system
PasswordPassword of the User
Port NumberThe port PowerShell runs on, by default, it is set to 5985
Remote Computer NameIP Address of the remote system
Use SSLIf enabled, it will use a secure connection and thus need to change the Port Number to 5986

For further information on Modules, visit the Decisions Forum.

Was this article helpful?

What's Next