Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have all the tasks from a server in a XML file obtained using

schtasks /Query /XML ONE>C:\schedtasksBackup.xml

Now, I want to import all the tasks in another server. All the info explains how to import o create ONE task at a time, but not multiple tasks at the same time.

It's possible? Or do I need to split the file in multiple atomic tasks file?

share|improve this question

I believe that if you want to use schtasks you need to make them atomic. I would recommend that you use the new-task cmdlet in powershell if you want to schedule multiple tasks (or just want more granular options) see PowerShellPack if you do not already have the resource kit installed.

share|improve this answer
up vote 0 down vote accepted

I wrote this code to split the xml and import the tasks one by one:

var taskXML = new XmlDocument();
var batbody = new StringBuilder();

XmlNodeList tasks = taskXML.DocumentElement.GetElementsByTagName("Task");

string strFileName = "d:\\temp\\Task";

for (int i = 0; i < tasks.Count; i++) {
    string onetaskXML = tasks[i].OuterXml;

    //Create the New File. With a little more extra effort
    //you can get the name from a comment above the task
    XmlWriter xw = XmlWriter.Create(strFileName + "_" + (i+1) + ".xml");
    batbody.AppendLine(string.Format("schtasks.exe /create /TN \"{0}\" /XML \"{1}\"", "Task " + (i+1) + " Name", strFileName + "_" + (i+1) + ".xml"));

    //Write the XML

    // Write a bat to import all the tasks
    var batfile = new System.IO.StreamWriter("d:\\temp\\importAllTasks.bat");


Edit: BUT, it wasn't so easy. I couldn't find why, but schtasks.exe gives malformed XML error importing the file. I have to import the files manually (hate it, but didn't have more time to spend on the issue)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.