- My View
Thank you Chris, but i saw this post before and it was not realy helpful because they use the runbook plugin (orchestration)
Do yu get any informations regarding this? If yes, please share it,even i would like to know about this.
Hi C Johnny,
I have not found anything yet.
Hi Carl Hensley,
your post sounds good. And I tried it but I get the error message 'no message handler for this message'.
I use this values:
Agent: my MID-Server
Name: for example whoami or ls
But it doesn't work. Do you know why?
Hi Tom Paulin,
I was able to execute both traditional DOS commands as well as PowerShell commands via the MID server ECC Queue.
Topic: Command <-- Command means use the Windows cmd.exe interpreter. I haven't been able to use "PowerShell" as the topic.
Name: powershell Set-ADUser jsmith -OfficePhone '123-555-1234'
However, there is an easy workaround. Just like above, preface all PowerShell commands with the word powershell. So above I put "powershell Set-ADUser ...."
If you want to run "ls" just do "powershell ls"
or "powershell Get-ChildItem"
All this does is tell cmd.exe to run powershell.exe and then the PowerShell command that follows.
Edited to Add: For certain PowerShell and regular Commands, the Windows account the MID Server service is running under matters. By default, a ServiceNow MID Server installed on a Windows Server box will probably run as "Local System account." For certain commands on a Windows Domain, you have to go to services.msc and then the "Log On" tab and change it to a domain account with enough rights. Otherwise all commands will run locally on the Windows Server and be blind to the rest of your company.
I found a way to execute PowerShell directly instead of calling cmd.exe first. It involves simply embedding the command in the ECC Payload in XML. I used value="ls -l c:\\" but it can be changed to any command.
// PowerShell directly! var ecc = new GlideRecord("ecc_queue"); ecc.initialize(); ecc.agent = "mid.server.MID_SERVER_NAME_HERE"; ecc.topic = "Powershell"; ecc.name = "Windows - PowerShell"; ecc.queue = "output"; ecc.state = "ready"; ecc.source = "127.0.0.1"; ecc.payload = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="skip_sensor" value="true"/><parameter name="probe_name" value="Windows - Powershell"/><parameter name="script.ps1" value="ls -l c:\\"/></parameters>'; ecc.insert();
Good one, David!
Just wanted to add that as you are not expecting a sensor to react to your probe, add the next parameter to the ECC Payload XML:
<parameter name="skip_sensor" value="true"/>
Otherwise the ecc queue message returned by the MID server (input) would go to "State: error".
There is actually an API for this, you don't need orchestration:
var probe = SncProbe.get("Windows - Powershell");
probe.setName("Windows - Powershell");
probe.addParameter("script.ps1","get-service -name sn_mid_server -computername ' + start_host + ' | set-service -status running");
probe.create("MID SERVER FULL SERVICE NOW NAME");
Platform Integration Architect
I have a doubt. What does script.ps1 denote in your code ?
I am struggling to know why is the script.ps1 parameter used ? And is it something which is stored in servicenow ?
If yes, please tell me where can i find it.
Platform Integration Architect