Migrate scheduled tasks from 2003 to 2008

Well, the time has come for me to learn at last syntax for schtasks what I was reluctant to do. Some time you have to migrate a task or a bunch of them from one computer to another. In my case it was even more “interesting” task: migrate some tasks from Windows Server 2003 box to Windows 2008 R2. If you have only one it is no problem to move it manually, but what if there are many of them? Here it is: the moment of schtasks’ triumph! =)

What it can do for us is to export 2003’s tasks into an XML file. Suppose we have task “Command Prompt” which launches cmd.exe once:




Now let’s use our secret weapon (we have to run it from a 2008 box, which has access to our 2003 server):


In Task.xml we now have the following content:

   1: <?xml version="1.0" encoding="utf-16"?>

   2: <Task version="1.1" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">

   3:   <RegistrationInfo>

   4:     <Author>trofimov</Author>

   5:   </RegistrationInfo>

   6:   <Triggers>

   7:     <TimeTrigger>

   8:       <Enabled>true</Enabled>

   9:       <StartBoundary>2011-04-10T23:43:00</StartBoundary>

  10:     </TimeTrigger>

  11:   </Triggers>

  12:   <Settings>

  13:     <Enabled>true</Enabled>

  14:     <DeleteExpiredTaskAfter>PT0S</DeleteExpiredTaskAfter>

  15:     <ExecutionTimeLimit>PT259200S</ExecutionTimeLimit>

  16:     <Hidden>false</Hidden>

  17:     <WakeToRun>false</WakeToRun>

  18:     <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>

  19:     <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>

  20:     <RunOnlyIfIdle>false</RunOnlyIfIdle>

  21:     <Priority>5</Priority>

  22:     <IdleSettings>

  23:       <Duration>PT600S</Duration>

  24:       <WaitTimeout>PT3600S</WaitTimeout>

  25:       <StopOnIdleEnd>false</StopOnIdleEnd>

  26:       <RestartOnIdle>false</RestartOnIdle>

  27:     </IdleSettings>

  28:   </Settings>

  29:   <Principals>

  30:     <Principal>

  31:       <UserId>System</UserId>

  32:     </Principal>

  33:   </Principals>

  34:   <Actions>

  35:     <Exec>

  36:       <Command>C:\WINDOWS\system32\cmd.exe</Command>

  37:       <WorkingDirectory>C:\WINDOWS\system32</WorkingDirectory>

  38:     </Exec>

  39:   </Actions>

  40: </Task>

which we can now import to our W2008R2 box with schtasks or even through GUI:




Of course, doing that with schtasks is more efficient way to import more than one task, but GUI is much more spectacular 😉