how to trigger powershell script from Servicneow workflow?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 05:54 AM
how to trigger powershell script from Servicneow workflow?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 06:01 AM
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 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 06:03 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 06:36 AM
Do you mean in run script we can write this script? because in workflow Run Powershell activity is not available
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2022 11:15 PM
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