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

how to trigger powershell script from Servicneow workflow?

Gopika P S
Mega Contributor

how to trigger powershell script from Servicneow workflow?

7 REPLIES 7

Aman Kumar S
Kilo Patron

Hey,

Please follow below post:
Execute powershell script from ServiceNow workflow run script activity

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Valmik Patil1
Kilo Sage

Hi ,

Please find below sample script to execute power shell script

You can use script Activity in workflow.

// Define ecc_agent and ecc_agent_script_file
var pb = new global.PowershellProbe("xxxx_server_name", "127.0.0.1","");  //1: mid server name 2: mid server ip

// Parameter need to be sent as JSON
var obj = JSON.stringify({'param1': value1}); //need an Object sent as JSON string
pb.setScript(obj); // instead of obj you can pass script name which need to execute

// Execute
var objResponse = pb.execute(true);

 

Please let me know if you need any help

Thanks,

Valmik

 

Do you mean in run script we can write this script? because in workflow Run Powershell activity is not available

Yes ,

There is no separate power shell activity

you can use script activity for this and place your code there

sharing one more example which might help you

var pb = new PowershellProbe("EC2WINMID1", "127.0.0.1");

var script = "$myVarName = 'John Andersen'\n" +
             "Write-Host $myVarName\n";

pb.setScript(script);

var response = pb.execute(true);
gs.log("OUTPUT: " + response.output);
gs.log("ERROR: " + response.error);

Please mark it helpful and correct if answer given by me helped you

Thanks,

Valmik