I wrote this code to split the xml and import the tasks one by one:
var taskXML = new XmlDocument();
taskXML.Load(@"d:\temp\schedtasksBackup.xml");
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
xw.WriteRaw(onetaskXML.ToString());
xw.Close();
// Write a bat to import all the tasks
var batfile = new System.IO.StreamWriter("d:\\temp\\importAllTasks.bat");
batfile.WriteLine(batbody.ToString());
batfile.Close();
}
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)