PowerShell Module Basics
  • 05 Oct 2022
  • 2 Minutes to read
  • Dark
    Light

PowerShell Module Basics

  • Dark
    Light

Article Summary

Overview

Module Details

Installation LocationCore module
Step Location Integration > Powershell
Settings Location N/A
PrerequisitesN/A

The PowerShell Module allows the execution of Powershell scripts from Flows. An instance cannot run Powershell scripts without installing this module.

PowerShell supports numerous plugins for integrating with system software and enterprise applications. Powershell can only run via remote connection



Run Powershell Remotely

All PowerShell steps run remotely. This exposes new inputs to specify which machine to remotely run the script and uses "WS-Management-based Windows PowerShell remoting". Users must add the IP of the VM to the TrustedHosts list during configuration by entering the following command:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value (IP Address)


To verify that the command works, use the following Powershell command:

Get-Item WSMan:\localhost\Client\TrustedHosts

This will allow Powershell to be run remotely as described in this article: Computer Trusted Hosts.

Troubleshooting - Enabling Powershell Remoting

While not required for the Powershell module or for enabling remote connection, Administrators experiencing difficulties with the above option may instead enable Powershell Remoting.

This method enables remote Powershell connections by calling the server itself remotely. 

By default, WS-Man and Powershell remoting use ports 5985 and 5986 for connections over HTTP and HTTPS, respectively.

Open Powershell as an Administrator to enable remoting and run the following command.

Enable-PSRemoting -Force 

The following response should be returned:


Example

  1. In Decisions Studio, navigate to System > Integrations > Powershell Script Projects. Right-click Powershell Script Projects and click Add Script Project.
  2. On the Add Script Project window, enter a name for the Script Project that will be used and click SAVE. This name will be used as a category in the Flow Designer to group Powershell steps.
  3. Right-click on the new Powershell Script Project and click Add Script.
  4. On the Add Script window, enter a name for the script under ScriptName and the code under Script. If applicable, add input and output values.
    Criteria for input values:
    • Must be strings
    • Must match the PowerShell token name exactly (without the $ symbol). For example, if a user wants to set the value of the $TextFilePath variable in the script, put TextFilePath in the Inputs section of the script editor.
    • Array input can be inputted as a comma-separated list. This mimics the behavior of the Windows PowerShell Console, i.e. if a user wants to set the value of the variable in Get-Process $ProcNames a valid input value for that could be Chrome, Explorer, Skype.
    Criteria for outcome values:
    PowerShell steps cannot return structured data, however, when a script returns an object, users can specify members of that object to return as string arrays. For example, the Get-Process cmdlet returns Process objects which have properties including ProcessName and Id. These properties can be specified as outputs of the step which are then outputted as string arrays at runtime. For more information, see Process Objects.

  5. Click SAVE to return to Powershell Script Project. 
  6. Create a new Flow.
  7. Navigate to INTEGRATION > POWERSHELL > [Script Project Name]. Add the script step to the workspace. The values entered for the INPUTS and OUTPUTS categories should show up on the step.


For further information on Modules, visit the Decisions Forum.

Was this article helpful?