PowerShell remoting for Discovery

  • Release version: Yokohama
  • Updated January 30, 2025
  • 2 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of PowerShell remoting for Discovery

    The PowerShell remote execution framework in ServiceNow Discovery enables probe developers to run PowerShell scripts automatically on remote target devices. This unified approach ensures consistent, efficient, and stable remote script execution across different environments, simplifying probe development and improving discovery accuracy.

    Show full answer Show less

    Requirements

    • The MID Server must have read and write access to the target device’s network share.
    • The remote target must have PowerShell version 3 or higher (up to 5.1).
    • For MID Servers using WinRM or WMI that copy scripts to the target, the MachinePolicy and UserPolicy execution scopes must be set to Undefined.
    • If scripts are executed without copying, the PowerShell execution policy can be more restrictive.

    Application Discovery and Script Execution

    • The framework supports copying scripts to the remote target, which is necessary for certain probes like Windows — File discovery that invoke themselves remotely.
    • Copying scripts helps avoid errors caused by long scripts when using WMI-based execution.
    • To prevent anti-virus interference, scripts copied to remote targets should be added to the permitted list in the target’s anti-virus software.

    Probe Configuration

    Within probes such as the Windows — Active Connections probe (part of the Windows — ADM multiprobe), configuration options allow control over remote script execution:

    • Execute script remotely: When enabled, scripts run on the remote target instead of the MID Server.
    • Copy script to target: When enabled along with remote execution, scripts are copied to and executed on the target. If disabled, scripts execute remotely without copying.

    PowerShell Probe Development

    Probe developers write PowerShell scripts as if running locally on the target. The remote execution framework transparently manages running these scripts remotely, regardless of whether the MID Server uses WMI or WinRM for communication.

    • MID Servers using WMI rely on launchProcess to run scripts remotely, which can be complex and prone to failure.
    • MID Servers using WinRM avoid launchProcess, resulting in more efficient and stable execution.

    This framework eliminates the need for developers to implement their own remote execution logic, reducing inconsistencies and improving overall probe reliability.

    Probe developers can use the PowerShell remote execution framework to automatically handle remote execution of scripts on target devices. The unified framework removes inconsistencies in remote execution, increases efficiency, and improves stability.

    Requirements

    To use PowerShell remote execution framework, the following requirements must be met:
    • The MID Server must be able to write to and read from the network share of the target.
    • The remote target must have PowerShell 3 or higher (up to 5.1).
    • For MID Servers using WinRM or WMI which choose to copy the script to the remote target, the MachinePolicy and UserPolicy scopes must be set to Undefined. If the script is not copied, the execution policy can be any other setting up to Restrictive.

    See Set up MID Servers to use PowerShell for more information.

    Application discovery

    The PowerShell remote execution framework has options for copying files to the remote target when executing a scan. Copying files to the target is important for probes like Windows — File discovery because its script invokes itself on the remote target to spawn off a new process. MID Servers using WMI to execute scripts remotely can experience an error with launchProcess if the script is too long. Copying the script to the remote target resolves this error. Copying a script to a remote target may result in anti-virus software on the target flagging the script. To avoid issues with anti-virus software, add the scripts to the permitted list in the anti-virus app.

    Probe configuration

    The following is the configuration page for the Windows — Active Connections probe, which is included in the Windows — ADM multiprobe.

    Windows — Active Connections probe configuration page

    The Execute script remotely check box is visible when the ECC queue topic is WMIRunner or PowerShell. When checked, the script executes on the remote target. Otherwise the script executes on the MID Server.

    The Copy script to target check box is visible when Execute script remotely is checked. If Copy script to target is checked, then the script is copied to, and run on, the target. If Copy script to target is unchecked, then the script is executed on the target without copying it.

    PowerShell probe development

    PowerShell remote execution framework is a unified method of executing PowerShell scripts, contained in a probe parameter, on a remote target server. The framework removes the need for probe developers to write their own remote execution code, which can cause inconsistencies between developers. The probe developer writes the script as if the probe was collecting information locally because the remote execution framework automatically handles remote script execution.

    The framework handles remote execution whether the MID Server is configured to use WMI or WinRM. If the MID Server is configured for WMI, the probe uses launchProcess to execute commands on the remote target. Using launchProcess complicates remote execution and can cause failures. However, a MID Server configured for WinRM does not use launchProcess, and so is more efficient and stable.