Trigger a windows task on a mid server

User485076
Tera Contributor

Hi,

Is it possible to trigger a windows task on a mid server from a script? Here is my script:

 

Unsure on the command and payload part. Any help would be greatly appreciated 

 


var midServerName = 'MID_SERVER_NAME';
var taskName = 'test task';

var midServer = new GlideRecord('ecc_agent');
midServer.addQuery('name', midServerName);
midServer.query();

if (midServer.next()) {
// Create a new ECC task record
var eccTask = new GlideRecord('ecc_queue');
eccTask.agent = midServer.sys_id; // Assign the MID Server's sys_id to the agent field
eccTask.queue = 'output';
eccTask.topic = 'Command';
eccTask.name = 'Trigger Scheduled Task';
eccTask.state = 'ready';

// Set the command payload to trigger the scheduled task
var command = 'cmd.exe /c schtasks /run /TN "' + taskName + '"';
eccTask.payload = command;

 

// Insert the ECC task record
eccTask.insert();

gs.info('ECC task created to trigger the scheduled task: ' + taskName);
} else {
gs.error('MID Server ' + midServerName + ' not found!');
}

6 REPLIES 6

@User485076 

I believe I have answered your original question for which you can mark my appropriate response as correct.

I already responded to your subsequent question.

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

@User485076 

for the next question check this

check these links on how to fetch it and add to table

File Import (CSV / XLS) file from Mid Server location

CSV file from MIDserver to ServiceNow instance

How to import excel file from Mid Server to import set table in service now.

How to import a CSV file from a MID Server

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