Automating Tasks with ServiceNow Probes: Running PowerShell Scripts with IP and Credential Parameters

ServiceNow offers a powerful tool for automating tasks and monitoring systems: probes. Probes are scripts that can be executed on a schedule or in response to a trigger, allowing you to automate tasks such as collecting data, checking the status of a service, running a performance check, or even executing other scripts. One particularly useful application of probes is the ability to run PowerShell scripts and pass both an IP address and a credential to the script. In this article, we will explain how to set up and execute a probe that runs a PowerShell script, passing both an IP and a credential as parameters.

The first step in creating a probe to run a PowerShell script is to create a probe parameter for the script itself. This parameter should be named with the ‘.ps1’ file extension, as this tells ServiceNow that the value of the parameter is a PowerShell script. The value field of the parameter should be the actual script you wish to run.

Next, you will need to create a probe parameter for the credential that you wish to pass to the script. This parameter should be named ‘credential_id’, and its value should be the sys_id of the credential in ServiceNow. The sys_id can be found by navigating to the Credentials module in ServiceNow and locating the appropriate credential.

Once you have created the probe parameters, you can access the values in your PowerShell script. The IP address and credential will be passed to the script as variables named $computer and $cred, respectively. However, it is important to note that the $cred variable will only work if the “Used by Orchestration” flag is set for the probe. It is also worth mentioning that the probe parameter for the script and the credential must be set as “Input” parameters so that the script can access them.

In summary, running a PowerShell script using a probe and passing both an IP and a credential is a straightforward process. By creating probe parameters for the script and credential and setting the “Used by Orchestration” flag, you can easily access the values in your script and automate tasks with ease.