PowerShell Module BasicsLast Updated: 04/06/2018 Introduced in Version: 2.0
Before using the PowerShell module you must have PowerShell 3.0 installed on your Decisions server. Please see this document from Microsoft on how to install this PowerShell prerequisit: Installing Windows PowerShell. If you run the Decisions PowerShell steps and do not have Windows Management Framework 3.0 installed on your Decisions server, you will get the following error: “Could not load file or assembly ‘System.Management.Automation, Version=188.8.131.52“
PowerShell Module – Use and Examples
After deploying the PowerShell module, browse to /System/Designers/PowerShell Script Projects/ in the Decisions portal. This is where you will create PowerShell scripts.
Click on Add Script Project. The name you give your script project will be used as a category in the flow designer to group your PowerShell steps.
After creating a Script Project, you will need to add scripts in your Script Project. Each script you add will become a flow step. Open your script project and click Add Script.
Enter a name and a script, and if applicable, input and output values. Below you will find explanations for how to enter these values.
- Inputs must be strings
- Inputs must match the PowerShell token name exactly (without the $ symbol). i.e. if you want to set the value of the $TextFilePath variable in your script, you need to put TextFilePath in the Inputs section of the script editor.
- Array input can be inputted as comma separated list. This mimics the behavior of the Windows PowerShell Console. E.g. if you want to set the value of variable in Get-Process $ProcNames a valid input value for that could be chrome, explorer, Skype
The powershell steps cannot return structured data, however when a script returns an object, we can specify members of that object to return as string arrays. E.g. the Get-Process cmdlet returns Process objects which has properties including ProcessName and Id. These properties can be specified as outputs of the step which are then outputted as string arrays at runtime. See here for more details on powershell object property extraction.
After saving your script, you will find it as a step in the flow designer toolbox under Integration/PowerShell/[Script Project Name]. Drag your script/step onto the design surface as you would any other step. The values you entered for Inputs and Outputs should show up on your step as they would on any other step.
Running PowerShell Scripts Remotely
All PowerShell steps have an option to Run Remotely. Enabling this option exposes new inputs which allows the user to specify which machine to remotely run the script. This “Run Remotely” option uses “WS-Management-based Windows PowerShell remoting” (see here for more details).
Below are links to example scripts and a flow that uses these scripts: these zip files can be imported to Decisions and illustrate the different ways the PowerShell module can be used.