ServiceNow runs PowerShell through a PowerShell step in Integration Hub, not through a separate spoke. The step needs an Integration Hub subscription and is used inside custom actions by people with the action_designer role. Scripts run on a MID Server, and action inputs reach the script as variables.
What people mean by a PowerShell spoke
A spoke in Integration Hub is a packaged set of actions for one system. PowerShell is different: it is a step you place inside a custom flow action (see the action explainer), and the script itself runs on a MID Server rather than on the instance.
The step requires an Integration Hub subscription. Users with the action_designer role can create a custom action with one or more action steps, and the PowerShell step is one of the steps available to them.
Prerequisites on the MID Server host
The script does not run in the instance, so the first checks happen on the Windows machine that hosts the MID Server.
The MID Server requirements cover Windows hosts only. On those hosts the MID Server needs a minimum PowerShell version of 3.0 and supports versions up to 5.1, plus PowerShell 7.
Two quick ways to see which version a MID Server is on:
- In the instance, open the MID Server list, personalize the list columns, add Host PowerShell Version to the selected columns. Sort by it to find servers on outdated versions.
- On the host, run the host version command in a PowerShell console and read the PSVersion value.
Using a newer PowerShell version
ServiceNow supports PowerShell 3.0 to 7.4 for the step, but by default Integration Hub uses 3.0 to 5.1. To use a newer version, add the MID Server property mid.property.ihub.prefer_powershell6Plus and set it to true.
PowerShell 6.0 and later is not pre-installed on MID Servers, so you install it yourself. The older range (3.0 to 5.1) and the newer range (6.0 to 7.4) can exist side by side on the same MID Server, so test your scripts before moving to a newer version.
PowerShell 3.0 does not support Windows 2003 Server.
Discovery has its own limits
Discovery is a separate concern from Integration Hub. In Xanadu, Discovery supports PowerShell 3.0, 4.0 and 5.0 for regular discovery, application dependency mapping and file-based discovery, and PowerShell 6.0 is not supported. If one MID Server serves both Discovery and flow actions, that difference matters when you pick a version.
Execution policy
Windows defines four execution policies:
| Policy | What it allows |
|---|---|
| Restricted | No scripts can be run; PowerShell works only interactively |
| AllSigned | Only scripts signed by a trusted publisher can run |
| RemoteSigned | Downloaded scripts must be signed by a trusted publisher |
| Unrestricted | No restrictions; all scripts can run |
With any policy other than Unrestricted, the script needs to be signed. Customers set the policy through their group policy settings. A script that runs fine on a developer laptop can therefore fail on the MID Server host because the host policy is stricter, so compare the two before you debug anything else.
Adding the step to a custom action
Open the action you are building and add the PowerShell step. The step has a handful of settings that decide where and how the script runs.
Remoting type
Remoting type sets the location where the script runs. There are three choices:
- Explicit Remoting (the most common choice) connects to a remote server and runs the script there.
- Implicit Remoting (the advanced choice) runs the script on a MID Server while importing the modules it needs from a remote server.
- The default option runs the script on the MID Server, or lets the script establish its own remote session.
Two fields depend on this choice. Modules to import takes a comma-separated list and is visible for Explicit and Implicit Remoting. Remote name prefix is visible only for Implicit Remoting, and it sets the file path to the modules on the remote server. For Implicit Remoting, leaving Modules to import blank imports all available modules. For explicit and implicit remoting, a function that takes input parameters must define a param block.
Script type
Script type offers two choices. An inline script is typed into the Command field of the step. A MID Server script file is picked from the MID Server Script Files table, and the step then shows a read-only Script path for the chosen file. The Command field is visible for inline scripts only, and the MID Server Script and Script path fields are visible for script files only.
The file option is the default. It separates the PowerShell from the action, so you can change the script without redeploying the action itself.
Passing inputs into the script
Each input variable on the action has a name, a type and a value. Input types are plain text, encrypted and boolean. By default a variable named message is read in the script as the message variable with a dollar-sign prefix. If the MID Server parameter that controls parameter passing (mid.powershell.command.script.parameter_passing) is set to false, the variable is instead read through the environment-variable form with the SNC_ prefix.
Some names cannot be used for inputs because they are reserved for internal processing: script, useCred, isMid, isDiscovery, debug, user, password, executingScriptDirectory, midScriptDirectory and hresult.
Encrypted values show as plain text in the field and are encrypted only while they pass to the ECC Queue. Keep secrets in credentials rather than in inputs wherever you can.
What happens when the step fails
The step has an If this step fails setting. You choose whether the action continues to the next step or goes to error evaluation.
Connections and credentials
For the wider concept, see the connection and credential alias explainer. The Connection setting lets you either define the connection inline or use a connection alias. An alias is the better choice when the same action will run against more than one environment, because you change the alias and leave the action untouched.
The fields shown depend on that choice:
- With Use Connection Alias, the Connection Alias field appears. People with the flow_designer or admin role can create or select the alias record, and the credential is exposed as a two-way encrypted password data pill.
- With Define Connection Inline, the Credential Alias field appears, along with Host (the fully qualified domain name of the target), Port (for example 5985, and blank uses the default port) and the MID server selection options.
MID server selection can be automatic, a specific MID Server, or a specific MID cluster. With automatic selection you name the MID application and its capabilities, and the application is referenced by name rather than as a record.
Reserved variables for connection details
When the Remoting Type is the default option that runs on a MID Server, three reserved variables are available to the script:
- computer holds the host IP address defined in the connection alias record.
- cred holds the credential object from the connection record, which you can pass to cmdlets such as New-PSSession with the credential parameter.
- log_info adds logging when the MID Server property mid.property.powershell.log_info is true.
Working through a first build
If the MID Server itself is not yet installed, start with the MID Server installation guide.
A sensible order for a first build keeps the number of moving parts low:
- Confirm the MID Server host version, using the list column or the host console.
- Check the host execution policy and sign scripts if the policy is not Unrestricted.
- Confirm you hold the action_designer role and that the instance has an Integration Hub subscription.
- Create a credential and a connection alias that points at the target host.
- Build a small action with one input and an inline script that returns a simple value, and use the Test PowerShell Step button on the credential.
- Move the script to a MID Server script file once it works.
Frequently asked questions
Is there a separate PowerShell spoke to install?
No. PowerShell is a step you add to a custom flow action. It requires an Integration Hub subscription, and the action designer role lets a person build actions that use it.
Where does the script actually run?
By default the script runs on a MID Server hosted on Windows. Remoting type decides whether it runs directly on the MID Server, on an explicitly named remote server, or through implicit remoting with imported modules.
Which PowerShell version should the MID Server host use?
On Windows hosts the MID Server needs PowerShell 3.0 at minimum and supports up to 5.1, plus PowerShell 7. For the step, ServiceNow supports 3.0 to 7.4: Integration Hub defaults to 3.0 to 5.1, and a newer version is used once it is installed and the prefer_powershell6Plus property is set to true.
Should I use an inline script or a script file?
The script file option is the default and keeps the script apart from the action, so edits do not need the action to be redeployed. Inline suits short commands entered in the Command field.
How do I pass a value from the flow into the script?
Create an input variable on the action. In the script it is read with a dollar-sign prefix, unless the parameter passing setting is false, in which case the SNC_ environment-variable form applies.
Why does my script work locally but fail on the MID Server?
A stricter execution policy on the host is one cause. If the policy is anything other than Unrestricted, scripts must be signed.