Output Scheduled Tasks to XML

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


Here's an easy way how you can export and dump a task that you created in "Scheduled Tasks" to XML:

function Export-ScheduledTask {
    schtasks /QUERY /TN $TaskName /XML | Out-File $XMLFileName

Specify the name of a scheduled task and a path to some XML file. If you are not sure what the names of your scheduled tasks are, this is how you can list the names of all scheduled tasks you can access:

PS> schtasks /QUERY


Twitter This Tip! ReTweet this Tip!


Posted Apr 16 2012, 06:00 AM by ps1


Irwin Strachan wrote re: Output Scheduled Tasks to XML
on 04-16-2012 11:08 AM

To get the exact Schedule Task name use: schtasks /Query /FO List.  I tried the following on my system:

Export-ScheduledTask -TaskName "Consolidator" -XMLFileName "$pwd\results\xml\Consolidator.xml"

It generated an error

Export-ScheduledTask -TaskName "Consolidator" -XMLFileName "$pwd\results\xml\Consolidator.xml"

schtasks.exe : ERROR: The system cannot find the file specified.

At line:8 char:7

+       schtasks /QUERY /TN $TaskName /XML | Out-File $XMLFileName

+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   + CategoryInfo          : NotSpecified: (ERROR: The syst...file specified.:String) [], RemoteException

   + FullyQualifiedErrorId : NativeCommandError

I found the correct path:

Export-ScheduledTask -TaskName "\Microsoft\Windows\Customer Experience Improvement Program\Consolidator" -XMLFileName "$pwd\results\xml\Consolidator.xml"

This worked fine... And now off to figure out how to import it back :-)

Copyright 2012 PowerShell.com. All rights reserved.