# Export Scheduled Tasks Using PowerShell

Posted on January 30, 2013 by Jeff Hicks in PowerShell with

When Microsoft revised the Task Scheduler in Windows Vista, one major piece they worked on the use of XML for the task definition. The benefit to you is that you can export a scheduled task and import it on a totally different machine. While the techniques I’m going to demonstrate should work for just about any scheduled task, I’m assuming you intend to use them with a custom task that you have created.

In this first article, I’ll show you specifically how to export scheduled tasks using PowerShell and the Management Console. In a follow-up article, I’ll discuss importing scheduled tasks in PowerShell.

## Export a Scheduled Task from the Management Console

The easiest way to export a schedule task is to use the Task Scheduler management console. Find the task, then right-click it and select Export from the context menu.

I have a scheduled task that generates a text report using the SystemInfo.exe command line tool. I created it on my Windows 8 box and would like to add it on other computers. When prompted, I’ll save the XML file to a central location. The exported file will default to using the task name as the file name. Some task names are a bit verbose so feel free to adjust accordingly.

Note: One potential downside to this approach is that you can only export one task at a time.

## Export a Scheduled Task from PowerShell

An alternative, and one that lends itself if you want to export multiple tasks, is to use Windows PowerShell. Unfortunately, this will only work on Windows 8 or Windows Server 2012 as it requires the ScheduledTasks module. The cmdlet to use is Export-ScheduledTask. At a minimum all you need to do is specify the task name.

But as you can see below, the result may not be what you expected.

The cmdlet did exactly what it said it was going to do. You have to take the extra step of sending the output to a file.

If you have tasks with the same name but in different folders, then you’ll also need to use the –TaskPath parameter.

This also means it is relatively easy to export multiple tasks, especially from the same folder.

Get-ScheduledTask -TaskPath “\MyCompany\” | foreach { Export-ScheduledTask -TaskName $_.TaskName -TaskPath$_.TaskPath | Out-File (Join-Path “\\chi-fp01\IT” “$($_.TaskName).xml”) }

This command will get every scheduled task in the MyCompany task folder. Each task is exported and the result is saved to an xml file on the IT file share using the task name. From here it is very easy to backup ALL scheduled tasks.

I’ve used the –Whatif parameter to test what would have happened as you can see below.

Another major benefit to using PowerShell to schedule tasks is that you can export tasks from remote machines.

This will get the task that ends in WindowsBackup from CHI-DC03 and export it to an XML file in the IT share. The remote machine must be running Windows 8 or Windows Server 2012. But it isn’t too difficult to take some of my previous examples and apply them to one or more remote systems. In fact you may want to make this a scheduled task itself!

For single exports, using the Task Manager management console is the easier approach. And for older systems it is really your only choice. Although you can use the legacy SCHTASK.EXE command line tool to list the XML definition and pipe the text to a file:

But if you have Windows 8 or later, then PowerShell is an attractive feature and is by far the best approach for managing exports of multiple tasks or from multiple machines.

Tagged with ,