I needed to export scheduled tasks (the items visible from Windows Task Scheduler) to keep it safe as a future backup. But, the Windows Task Scheduler interface allows you to export only one task at a time. I was sure there was something available in good old PowerShell. And sure enough, there was!
Here’s a nifty PowerShell command that accomplishes this:
Get-ScheduledTask | ForEach { Export-ScheduledTask -TaskName $_.TaskName
-TaskPath $_.TaskPath | Out-File (Join-Path "X:\Backups\Tasks" "($_.TaskName).xml") }
But then, the above command will export ALL the tasks including the out of the box system ones. We are only interested in our own tasks. In my case, I prefix all of my tasks with “CUSTOM -
” and they all lie in the “\” folder of the Task Scheduler.
Task Scheduler “folders” or “Task Path” are the folders you see when you expand the “Task Scheduler Library” folder on the left pane in Task Scheduler UI.
So with these in mind, my PowerShell command becomes:
Get-ScheduledTask -TaskPath "\" | Where { $_.TaskName.Contains("CUSTOM -") } |
ForEach { Export-ScheduledTask -TaskName $_.TaskName -TaskPath $_.TaskPath |
Out-File (Join-Path "X:\Backups\tasks" "$($_.TaskName).xml") }
Feel free to suitably modify and use!