How to create payload in ecc queue?

Sathwik1
Tera Expert

Can someone help me to create payload in ecc queue..

I need to pass a powershell command through payload  so that command can perform some action in the midserver.

1 ACCEPTED SOLUTION

@Sathwik1 

I wrongly copied these 2 lines

try this

var value = "Get-ChildItem –Path \\'C:\\SathwikFolder\\' -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-10))} | Remove-Item";
var payload = '<?xml version="1.0" encoding="UTF-8"?><parameter name="name" value="' + value + '"></parameter>';

when I used this it didn't give me xml error

see output below

XML Error.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

21 REPLIES 21

@Sathwik1 

I think issue with single quote or double quotes

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Sathwik1 

update as this

var gr = new GlideRecord('ecc_queue');
gr.initialize();
gr.agent='mid.server.DevMID_ServerCluster1';
gr.topic='Command';
var value = 'Get-ChildItem –Path \\"C:\\SathwikFolder\\" -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-10))} | Remove-Item';
gr.state = 'ready';
gr.payload = '<?xml version="1.0" encoding="UTF-8"?><parameter name="name" "value="' + value + '"/></parameter>';
gr.queue = "output";
gr.insert();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Same issue ankur, tried again..

@Sathwik1 

I wrongly copied these 2 lines

try this

var value = "Get-ChildItem –Path \\'C:\\SathwikFolder\\' -Recurse | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-10))} | Remove-Item";
var payload = '<?xml version="1.0" encoding="UTF-8"?><parameter name="name" value="' + value + '"></parameter>';

when I used this it didn't give me xml error

see output below

XML Error.gif

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks @Ankur Bawiskar for your efforts, now I'm not getting error.. but somehow still in input queue still I'm getting status as error..

based on your latest code we are just passing command... but we didn't mention "Powershell -Command" will it work without this?