PowerShell Module Basics
  • 20 Dec 2024
  • 2 Minutes to read
  • Dark
    Light

PowerShell Module Basics

  • Dark
    Light

Article summary

Module Details

Installation LocationCore module
Step Location Integration > Powershell
Settings Location N/A
PrerequisitesPowerShell Module Installed
Project Dependency made

Overview

The PowerShell Module allows the execution of PowerShell scripts from Flows.

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

Security Risk
This add-on module provides scripting capability.  Administrators acknowledge and accept full responsibility for securing the environment ahead of installing and using it.

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:

Limitations of PowerShell in Containers
In containerized environments, the 'Run Remotely' option on PowerShell steps, which facilitates remote script execution, is not supported.
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 a Project, navigate to [Project Name] > Manage > Integrations > Scripting>  Powershell. Right-click Powershell Script Projects and click Add Script Folder.
  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. There is also an Add Script action towards the top of the folder. In v9.6 and above, script folders can be deleted by right-clicking the folder, then selecting Manage | More > Delete.
  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.
    Input values must be strings, match the Powershell token name minus the dollar $ symbol, and allow array input via a comma-separated list to mimic Powershell Console behavior.
    Output values cannot return structured data; however, a script returning an object can specify its data members to return as string arrays. For further information, refer to the "Process Class" article in Microsoft's documentation.


  5. Click SAVE to return to Powershell Script Project. 
  6. In a Flow Designer, navigate to Integration > Powershell > [Script Project Name]. Add the script step to the workspace. The values entered for the Input and Output categories should appear on the step.
Refer to the next article to learn more about the PowerShell Script Step Outputs.

Feature Changes

DescriptionVersionRelease DateDeveloper Task
ADD SCRIPT FOLDER action is now available in the main Powershell folder.9.2August 2024[DT-041378]
Script folders now have a delete action.9.6January 2025[DT-042782]

Was this article helpful?