Migrating Scheduled Task Jobs

Finally retiring that old Windows Server 2003 machine? Need to migrate your scheduled tasks? Here is an easy solution.

One of our clients is finally migrating from Windows Server 2003 to Windows Server 2012 (don't judge) and I ran into an interesting problem. They have a bunch of jobs set up in the Task Scheduler that need to be migrated over, but the old machine uses a deprecated binary .job file format to store the job data, while the newer machine uses an xml-based file format.

Of course, there is a built-in solution for this problem: the schtasks program now has an /XML switch to export an xml file. However, that version of schtasks only works on the newer OSes, so you cant easily convert the scripts on your old machine.

Surely Google can help, right? It didnt take long to find several solutions like this that let you specify the remote host name of the older OS. In that case, you can use the newer schtasks (with xml export) but point it at the older machine and everything is easy-peasy.

But that only works if the two machines are on the same domain and can see each other. In my case, we were moving from one virtual hosting company to another, so the two machines could not interact in this way.

Back to Google and I find a long-winded but working solution that requires you to copy the old version of schtasks to the new machine, pipe some directory output to text file, manually create an Excel spreadsheet that gets saved as a .bat file and eventually execute schtasks on a copy of the old jobs. Whew - there had to be a better way! So I whipped one up.

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("username:");
            var username = Console.ReadLine();
            Console.WriteLine("password:");
            var password = Console.ReadLine();
            var files = Directory.GetFiles(@"c:\windows\tasks", "*.job");
            if (files == null || files.Count() == 0)
            {
                Console.WriteLine("No .job files found to process");
            }
            else
            {
                foreach (var file in files)
                {
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
                    var arguments = String.Format("/change /TN {0} /RU {1} /RP {2}", fileNameWithoutExtension, username, password);
                    var psi = new ProcessStartInfo(@"schtasksXP", arguments);
                    psi.UseShellExecute = false;
                    Console.WriteLine(psi.FileName + " " + psi.Arguments);
                    var p = Process.Start(psi);
                    p.WaitForExit();
                }
            }
            Console.WriteLine("DONE");
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
    }

To use it:

  • Copy your old .job files to C:\Windows\Tasks on the new machine
  • Download the .zip file and unzip the contents to a folder
  • Run TaskScheduleJobConverter.exe which will prompt you for a username & password to be used to execute the imported jobs

When the script completes, all of the old jobs will have been converted and imported into the new machine's Task Scheduler.

Download the program

 

@briandunnington


2018.11.27

Deploying Azure Web App Certificates from Key Vault

How to work around an ARM template limitation when using a Key Vault certificate in a Web App

View details »


2018.11.06

Roku Round-up

Quick updates on some Roku libraries that I recently released

View details »


2018.10.09

CORS and exceptions on ASP.NET Core

How to ensure your CORS headers are properly returned with HTTP error responses on ASP.NET Core

View details »


2018.03.25

The many uses of Azure Functions Proxies

Azure Functions Proxies are awesome - here are just a few ways to leverage them

View details »


2018.03.12

Build an Alexa skill using Azure Functions

Although AWS Lambdas are the default, it is dead simple to use Azure Functions for your Alexa skill as well

View details »


More Posts >