The CreatorCon Call for Content is officially open! Get started here.

How to pass parameters to a mid-server script files

Uma2
Tera Expert

Hi Team,

  I want to pass parameters into mid-server power shell script files.Can anyone help me how we can pass.

In below script i need to pass app_id value for the url.

find_real_file.png

Thanks,

Uma.

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

I think this is final. I tested it and works for me.

Scheduled Job

var ecc = new GlideRecord("ecc_queue");
ecc.initialize();
ecc.agent = "mid.server.XXXX";
ecc.topic = "Powershell";
ecc.name = "Windows - Powershell";
ecc.source = "10.XXXX";
ecc.queue = "output";
ecc.state = "ready";
ecc.payload = this._getPayloadString();
ecc.insert();

function _getPayloadString() {
    var xmldoc = new XMLDocument("<parameters/>");
    var el = xmldoc.createElement("parameter");
    xmldoc.setCurrent(el);	
    xmldoc.setAttribute("name", "skip_sensor");
    xmldoc.setAttribute("value", "true");

    xmldoc.setCurrent(xmldoc.getDocumentElement());
    el = xmldoc.createElement("parameter");
    xmldoc.setCurrent(el);
    xmldoc.setAttribute("name", "probe_name");
    xmldoc.setAttribute("value", "Windows - Powershell");

    xmldoc.setCurrent(xmldoc.getDocumentElement());
    el = xmldoc.createElement("parameter");
    xmldoc.setCurrent(el);
    xmldoc.setAttribute("name", "MIDScriptFile");

    xmldoc.setAttribute("value", _getScriptFilePath('e517b060db36d010d97f50aadc96191a'));
	
	xmldoc.setCurrent(xmldoc.getDocumentElement());
    el = xmldoc.createElement("parameter");
    xmldoc.setCurrent(el);
    xmldoc.setAttribute("name", "powershell_param_appid");
    xmldoc.setAttribute("value", '10555');

    return xmldoc.toString();
}

function _getScriptFilePath(file_id) {
    var scriptPath = '';
    var gr = new GlideRecord('ecc_agent_script_file');
    if (gr.get(file_id)) {
        var path = '';
        while (!gs.nil(gr)) {
            path = gs.nil(path) ? gr.name : gr.name + '\\' + path;
            gr = gr.parent;
        }

        scriptPath = 'scripts\\' + path;
    }

    return scriptPath;
}
$requestVersion = "vcode_request_version_1"

$method = 'GET'
$id = "$appid"
$urlBase = "xxx.xxxx.com"

$urlPath = "/api/5.0/getappinfo.do?app_id=$id"
$url="https://xxx.xxx.com/api/5.0/getappinfo.do?app_id=$id"

View solution in original post

29 REPLIES 29

Hi Mike,

  

$requestVersion = "vcode_request_version_1"

$method = 'GET'

$urlBase = "xxx.xxxx.com"

$urlPath = "/api/5.0/getappinfo.do?app_id="
$url="https://xxx.xxx.com/api/5.0/getappinfo.do?app_id="

 

 

Thanks,

Uma.

try

$requestVersion = "vcode_request_version_1"

$method = 'GET'
$appid = "$appid"
$urlBase = "xxx.xxxx.com"

$urlPath = "/api/5.0/getappinfo.do?app_id=" $appid
$url="https://xxx.xxx.com/api/5.0/getappinfo.do?app_id=" $appid

Hi Mike,

 

Can you share screenshot of Output?