Ref:
- How to mass export Tasks from Windows Task Scheduler
- Import a Task
- Iterating with “For”
- How to get filename only without path in windows command line?
- SchTasks.exe to create a task folder
- Task Scheduler Schema
Pointers:
- All the Tasks created in Windows are stored in the Task Folder of Windows System Directory which in my case is C:\Windows\System32\Tasks.
- Copy the task files to the machine you want to export to.
- Rename the files with extension as .XML. I have verified that this XML file is exactly the same as the XML file generated via Export function.
- The script below exports all jobs in a task folder. %%~nf extracts the file name of a file, which is the same as the task name. Note that there cannot be ‘.’ present in the task name as otherwise the content after ‘.’ is treated as extension.
for %%f in (C:\Windows\System32\Tasks\{task folder}\*) do ( copy /y "%%f" "{export folder}\%%~nf.xml" )
- The script below creates the jobs exported in the above step. Note that -F means it will override any existing task with the same name. /RU,/RP is used instead of /S /U /P because I cannot figure out what /S should be for local user…
for %%f in ("{export folder}\*.xml") do ( schtasks /create /xml "%%f" /tn "{task folder}\%%~nf" /RU "{domain\user_id}" /RP {pwd} /F )