MID Server not ending processes called through ECC queue

peter_schnack
Kilo Explorer

I will start off with be gentle.   This is the way I got this to almost work, but I am sure there is a better way. (We do not have Orchestration)

I am using a business rule to create a record on the ECC queue to execute a command, which is really a PowerShell script.   I had trouble executing the PowerShell script directly (and that might be the solution, and so that may be the help I need).   This is working but it is leaving both the PowerShell script and cmd processing on the MID server.   Also, the script runs VERY slow, like can take minutes to execute all the lines in the PowerShell script.  

If you execute this directly on the MID server it terminates properly and runs fast.

The script I am using in the business rule basically builds the following (sample)

...

queue.agent = 'mid.server.Test MID Server 1';
queue.topic = 'Command';
//queue.source = 'Business Rule Visitor';
queue.queue = 'output';
queue.state = 'ready';
queue.payload= '<parameters> <parameter name="name" value=' +C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell c:\ServiceNow\createbadge.ps1 -VisitorName 'Stan Smith' -Id 12345 -CompanyName 'Smith, Inc.' -SponsorName 'Mr. Smith' -Printer '\\Server\LabelPrinter' + '/></parameters>';
queue.insert();

So this prints just fine.   But again, the cmd and PowerShell script never terminate.   They also do not add a input record back on the ECC queue until you kill the processes on the MID server.   Then you get back an error similar to ...

<?xml version="1.0" encoding="UTF-8"?><results probe_time="213552"><result command="C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell c:\ServiceNow\createbadge.ps1 -VisitorName 'Steve Smith' -Id '12345' -CompanyName 'Smith, Inc.' -SponsorName 'Mr. Smith' -Printer '\\Server\LabelPrinter'"><stdout/><stderr/></result><parameters><parameter name="topic" value="Command"/><parameter name="queue" value="output"/><parameter name="error" value=""/><parameter name="from_sys_id" value=""/><parameter name="sys_id" value="4198821a6fb371006566211bbb3ee4bf"/><parameter name="state" value="ready"/><parameter name="sys_created_on" value="2015-05-05 16:56:35"/><parameter name="from_host" value=""/><parameter name="agent" value="mid.server.Test MID Server 1"/><parameter name="processed" value=""/><parameter name="ecc_queue" value="4198821a6fb371006566211bbb3ee4bf"/><parameter name="response_to" value=""/><parameter name="source" value=""/><parameter name="sequence" value="14d2501f8480000001"/><parameter name="name" value="C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell c:\ServiceNow\createbadge.ps1 -VisitorName 'Steve Smith' -Id '12345' -CompanyName 'Smith, Inc.' -SponsorName 'Mr. Smith' -Printer '\\Server\LabelPrinter'"/><parameter name="table_name" value="ecc_queue"/><parameter name="agent_correlator" value=""/></parameters></results>

It may just be that I need to call the PowerShell script directly, but again, that was not working for me.

Thanks for any help!

3 REPLIES 3

aray
Giga Contributor

Couple thoughts....



  • Don't think it's an issue calling it through powershell vs direct, we do it this way quite a bit
  • If it runs fine locally, but not well via the MID, my initial thought is an environmental difference.     Maybe put the powershell command in a batch file, and have it echo the environment from the MID and locally so you can compare.     (SET > output.txt)
  • Are you absolutely sure it's calling the script, and the script is actually running?     Do you have some sort of logging activity in your powershell that proves it's running?     If not, it might be you're calling powershell, and it's just waiting for user input, hanging before it actually calls your script.
  • If the PS is not actually running, I've seen issues with commands being sent to the MID with spaces (which it looks like you don't have), and backslashes.     I know in the past I've had to escape backslashes, since sometimes it will mess with the XML going to the MID.       IE: c:\\ServiceNow\\createbadge.ps1


Good luck!


Ray,



Thanks for the reply.   Just so that you know it runs either locally or via the MID.   They both complete the print job and everything is fine.   What happened was when I was trying to figure out why the script seemed to complete slow, I put some debug lines in and found that it was taking (from the MID) minutes to complete where running from the command line on the MID, it was taking less than 1 second.   Then I brought up the task manager and noticed that there were lots of cmd and PowerShell process running as I killed off the PS processes the cmd process would also go away and I would get the "input" record back on the ECC queue.  



Something is not right.


Thats a tough one.     I've had more experience with things just not running,   not running slow.      



Maybe comment out some of the lines in the PS and see if it still runs slow?     I would think the culprit is something inside the script that takes longer or is timing out due to enviornmental issues.