PowerShell probe
Summarize
Summary of PowerShell probe
The PowerShell Probe in ServiceNow executes PowerShell V2 scripts directly on the MID Server host. Users define the PowerShell scripts as probe parameters, specifying the script filename as the parameter name. This probe functions by setting the probe type to "Probe" and specifying "PowerShell" as the ECC queue topic.
Show less
Key Features
- Source Parameter: Defines the initial host to connect to; this is required.
- Script Filename: The PowerShell script file to execute, identified by the parameter named with the script’s filename (e.g., scriptname.ps1).
- Parameter Passing: Parameters for the script can be passed either as environment variables or on the command line. The parameter
powershellcommandparameterpassingcontrols whether parameters are passed on the command line, defaulting to false. All parameters are available as environment variables prefixed withSNCto the script. - Parameter Prefixes:
powershellparam: Passes parameters as plain environment variables without encryption.powershell: Passes parameters assuming they are encrypted, and the MID Server attempts to decrypt them.
Choosing the correct prefix is critical to avoid execution errors that are reported back in the ECC queue input.
- Debugging Options:
debug: Enables debug logging during probe execution.credentialsdebug: Adds a credentials debug section in the ECC queue to help troubleshoot credential issues, regardless of success.
Scripting Requirements
Custom PowerShell scripts must use environment variables to handle any non-Boolean parameters. Non-Boolean parameters defined in the script’s Param() block should be replaced by script variables that read their values from environment variables using the SNC prefix. For example, a string parameter $paramName should be assigned using:
if(test-path env:\SNCparamName) { $paramName = $env:SNCparamName}
This approach ensures compatibility with how the probe passes parameters and supports encrypted and non-encrypted inputs appropriately. Boolean parameters can remain in the Param() block.
Creating Custom PowerShell Probes
ServiceNow customers can create and configure their own PowerShell probes by defining the necessary probe parameters and scripts following the above conventions. This enables tailored automation and monitoring tasks executed on the MID Server host through PowerShell scripts.
The PowerShell Probe executes PowerShell V2 scripts on the MID Server host.
PowerShell scripts are defined as probe parameters with the filename as the parameter name. It is available as a Probe probe type by specifying PowerShell as the probe's ECC queue topic.
PowerShell probe parameters
| Parameter name | Description |
|---|---|
| source | [Required] The initial host to connect to. Default: None |
<script name>.ps1 |
[Required] The filename of the PowerShell script to run. Replace
<script name> with a valid filename
prefix. Default: None |
powershell_command_parameter_passing |
Specifies whether to pass script parameters on the command line. Regardless of this parameter's value, ServiceNow makes all script parameters on the command line automatically available to PowerShell scripts as environment variables. Default: false |
| powershell_param_<script parameter name> | Passes additional parameters to the PowerShell script to be executed. Each
parameter will appear to the script as an environment variable in the format
$env:SNC_<script parameter name>. Parameters with this
prefix are not considered encrypted and are passed through to the script untouched.
Make sure you select the appropriate parameter between
powershell_param_<script parameter name> and
powershell_<script parameter name>. Using the wrong prefix
results in errors in the PowerShell execution, which is passed back to the instance
in the ECC queue input. Default: None |
powershell_<script parameter name> |
Passes additional parameters to the PowerShell script to be executed. Each
parameter will appear to the script as an environment variable in the format
$env:SNC_<script parameter name>. The MID Server assumes
that any parameter with this prefix is encrypted and attempts to decrypt it. Make
sure you select the appropriate parameter between
powershell_param_<script parameter name> and
powershell_<script parameter name>. Using the wrong prefix
results in errors in the PowerShell execution, which is passed back to the instance
in the ECC queue input Default: None |
| debug | Enables debug log output during the probe. Default: false |
| credentials_debug | Displays a <credentials_debug> section in the ECC queue, which can help you
troubleshoot credentials. If you set this property to true, credential
troubleshooting information is output to the ECC queue, even if the credentials
succeed. Default: false |
Scripting requirements
Any custom PowerShell scripts must use environment variables to pass any non-Boolean command line parameter. Replace non-Boolean parameters in the Param() portion of the script with script variables of the same name. Define the script variable as part of the environment with an SNC_ prefix. So a string parameter such as this:
Param([string]$paramName)Becomes a script variable such as the following:
if(test-path env:\SNC_paramName) {
$paramName = $env:SNC_paramName
}For example, this parameter definition from the PSScript.ps1 script contains several string parameters that need to be redefined as script variables:
Param([string]$computer, [string]$script, [string]$user, [string]$password, [boolean]$useCred, [boolean]$isDiscovery, [boolean]$debug)Defining the non-Boolean parameters as script variables would result in this type of script:
Param([boolean]$useCred, [boolean]$isDiscovery, [boolean]$debug)
# Copy the environment variables to the params
if(test-path env:\SNC_computer) {
$computer=$env:SNC_computer
}
if(test-path env:\SNC_script) {
$script=$env:SNC_script
}
if(test-path env:\SNC_user) {
$user=$env:SNC_user
$password=$env:SNC_password
}