I want to save my scheduled tasks using powershell.
I tried this:
$taskpath = "\mytasks\" # all of my tasks are in this folder in Task Scheduler
$savefolder = "C:\tasks" # where I want to save the xml files
Get-ScheduledTask -TaskPath $taskpath | foreach { Export-ScheduledTask -TaskName $_.TaskName | Out-File (Join-Path $savefolder "$($_.TaskName).xml") }
Those paths exist.
But I get this error: Export-ScheduledTask : The system cannot find the file specified.
What am I doing wrong?
Best Answer
You missed to supply
TaskPath
intoExport-ScheduledTask
cmdlet:Use
Instead of specifying particular
TaskName
andTaskPath
parameters, you can pipeInputObject
object obtained fromGet-ScheduledTask
intoExport-ScheduledTask
cmdlet as in the following code snippet: