How to backup Windows Task Scheduler Tasks

backuptask-schedulerwindows-server-2008-r2windows-server-2012-r2

I need to backup Task Scheduler Tasks. These are already grouped into one subfolder within the Task Scheduler. But the only way I found, is to use

schtasks.exe /query /tn "<path>\<taskname>"

With that I have to specify every single task… but these could be different on different machines.

I'm searching for a simple way to use a wildcard.
E.g.

schtasks.exe /query /tn "<path>\*"

Is there a way, to

  • not export the whole list? (I really don't care about Microsofts own
    tasks like \Microsoft\Windows\Wininet\CacheTask)
  • export a whole folder?

Best Answer

Use Powershell. On Windows Server 2008 R2 , you can use the following code;

$x = New-Object -ComObject("Schedule.Service") ; $x.Connect() ; $x.GetFolder("\CustomTasks").GetTasks(1) | % {$_.XML | Out-File "C:\temp\$($_.Name).xml"}

This will export all the tasks under "CustomTasks" folder to C:\Temp folder and file names will be "WhateverTheTaskNameIs.xml" .

For Windows Server 2012 and later, you can use Get-ScheduledTask and Export-ScheduledTask cmdlets.