Trigger a windows task on a mid server
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 07:07 AM
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!');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 10:16 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 04:06 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader