Executing powershell command on mid server

vineetharohra
Kilo Contributor

I was earlier using following logic to create an entry in ecc queue to execute a powershell command(I've removed the before and after codes and pasted only main logic):

var payload = '<parameters>' +
'<parameter name="probe_name" value="Windows - Powershell"/>' +
'<parameter name="script.ps1" value=\'' + cmd + '\'/>' +
'<parameter name="skip_sensor" value="true"/>' +
'</parameters>';

var sysid = '';

var grECC = new GlideRecord('ecc_queue');
grECC.initialize();
grECC.agent = 'mid.server.' + gs.getProperty('MID SERVER NAME PROPERTY GOES HERE');
grECC.topic = 'Powershell';
grECC.name = 'Windows - PowerShell';
grECC.source = '127.0.0.1';
grECC.queue = 'output';
grECC.payload = payload;
sysid = grECC.insert();
return sysid; //being returned to from where the function was called

cmd contains a powershell command to create a csv file with some data in it.

When I am using above logic, it does not execute. 

I find an 'output' record in ecc queue with state processed, but its corresponding input record says

'Unable to find script(s) specified in parameters. Make sure the script(s) associated with probe are passed down properly.'

But, when I replace above logic with following, it does work perfectly:

var payload = '<parameters>' +
'<parameter name="probe_name" value="Windows - Powershell"/>' +
'<parameter name="script.ps1" value=\'' + cmd + '\'/>' +
'<parameter name="skip_sensor" value="true"/>' +
'</parameters>';

var sysid = '';

var probe = SncProbe.get("Windows - Powershell");
probe.setName("Windows - Powershell");
probe.setSource("127.0.0.1");
probe.addParameter("script.ps1",cmd);
probe.addParameter("skip_sensor", true);
sysid = probe.create('mid.server.' + gs.getProperty('agi.procurement.hcm.mid_server'));
gs.log('$$ sys id='+sysid);
return sysid;

 

In both cases, I am sending same command + same data in cmd variable, why does one execute and the other gives an error then ? What am I missing here ?

1 REPLY 1

vineetharohra
Kilo Contributor

The command I am passing in cmd is:

"echo SOME DATA GOES HERE | Out-File -Encoding utf8 -FilePath MY_MID_SERVER_FOLDER_PATH\prod\outbound\PO_IDs_20190214020008.csv"