Tuesday, October 9, 2018

Execute powershell script from ServiceNow workflow run script activity

var pScript = "Script that needs to be executed";
var powershell = new PowershellProbe('MID_SERVER_NAME', gs.getProperty('mid.server.ip'));
powershell.setScript(pScript);
var resp = powershell.execute(true);
workflow.scratchpad.error = resp.error;
workflow.scratchpad.output = resp.output;
if(!resp.output.nil() && resp.output ! = 'null')
   current.work_notes = resp.output;
else if(!resp.error.nil()) {
current.work_notes = 'Error in script:  ' + resp.error;
}
gs.log('Response Output ' + resp.output);
gs.log('Response Error ' + resp.error);

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.