Calling PowerShell script on MID server


Description

In this example, we create a scheduled job that calls a PowerShell script stored on the MID server in the relative path scripts\.

Instructions

1. Sample PowerShell script:


#Variables:


$arg1 = $args[0]

$arg2 = $args[1]


#Do some processing

$DisplayName = $arg1 $arg2


#Display output

WriteHost "Display name output: " $DisplayName

2. Store the PowerShell script in the MID Server folder path: scrips

3. Create the following script in the instance to insert an ECC Queue record so that MID Server can process:

var arg1 = "variable 1";
var arg2 = "variable 2";
var ecc = new GlideRecord("ecc_queue");
ecc.initialize();//to create record
ecc.agent = "mid.server.YOUR_MIDSERVER_NAME";
ecc.topic = "Command";
var value = "powershell scripts\\myScript.ps1 "+arg1+ " " +arg2;
ecc.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="name" 
value="'+value+'"/><parameter name="skip_sensor" value="true"/></parameters>';
ecc.queue = "output";
ecc.state = "ready";
ecc.insert();


4. Once the record is processed, the result of the script is written in the ECC Queue input.