New
#1
Export/Import Scheduled Tasks in bulk
I'm transferring files to another computer, and I've got a ton of scheduled tasks to move.
Is there a method or program for this?
I'm transferring files to another computer, and I've got a ton of scheduled tasks to move.
Is there a method or program for this?
To copy all the tasks to your folder E:\Backup\My Tasks
(You could decide to simply copy these with File Explorer instead, but that won't work if one or more tasks have a name that ends with a period [.] character, as File Explorer refuses to recognize filenames that end with a period even though such filenames are nonetheless valid NTFS filenames... I know it's funny, but you can verify this yourself by creating a new task named test. if you don't believe.)Code:@echo off set d=E:\Backup\My Tasks chcp 65001>nul copy \\?\%Windir%\System32\Tasks\*.* "\\?\%d%"
Next, on the other computer, assuming that your folder to which you have copied the tasks is now F:\Backup\My Tasks
(The last command will delete all the files from your folder if you choose to confirm, File Explorer can't delete a file if the filename ends with a period so, to delete a file F:\Backup\My Tasks\test. you could run del "\\?\F:\Backup\My Tasks\test." )Code:@echo off set d=F:\Backup\My Tasks chcp 65001>nul for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do ( schtasks /create /tn "%%~f" /xml "\\?\%d%\%%~f" ) del "\\?\%d%\*.*"
Last edited by hdmi; 20 Jan 2022 at 08:15.
I backup all my tasks using a batch file
1 I copy all the task files [task definition files] from C:\Windows\System32\Tasks & [only] from those subfolders of it that I have created [as subfolders of my TS library]. I do not blindly copy all subfolders because that would, quite uselessly, copy all the tasks that Windows had created.
2 I rename the extension-less files thus created to add back in their missing .xml extension
I import the results individually within TS if I ever need to. With some exceptions, importing the task definition within TS on another computer requires that the whole <UserId> line of the backed up task definition be deleted first. I just do this manually within Notepad.
I have not done any mass importation but would look to the SchTasks command for that.or I'd examine PowerShell's capabilities in this respectTask Scheduler cmdlets - SS64
Scheduler error codes - SS64
Get-ScheduledTask - MSDocs
Get-ScheduledTaskInfo - MSDocs
Set-ScheduledTask - MSDocs
Denis
Last edited by Try3; 19 Jan 2022 at 04:59.
Thanks guys, and I apologize that my apparent lack of knowledge prompted me to ask the wrong question, or begin with a flawed concept. I already have a backup folder with all my scheduled tasks, ready to import, one by one, if that's what I choose to do.
It should have dawned on me that there was a place in the OS, C:\Windows\System32\Tasks, where these scheduled tasks reside.
So let me restart by asking this. Can you simply copy and paste that Tasks folder from one computer to another, and have those tasks appear in the Task Manager?
I don't think so, no. You could always decide to use the second script I posted (but remember to substitute the folder location on the second line with the correct folder location, and, if you don't want the files to be deleted from the folder, then also remember to remove the del command that's on the last line...).
Task scheduler?
They need to be imported within TS or by using SchTask*** commands. If you merely copy them back into C:\Windows\System32\Tasks on the new computer then TS will detect them as having been tampered with and it will refuse to run them.
*** Or the PowerShell equivalents - see ScheduledTasks - MSDocs
As I said above,
- This applies to the tasks you have created yourself.
- I've transferred task run by the System 'user' without having had to remove that line.
Denis
Last edited by Try3; 20 Jan 2022 at 03:54.
With schtasks you can use the /RU and /RP (create options) to avoid this. The following batch code should work even if the <UserId> element has not been deleted first, but it will ask you to type your password, which is a minor inconvenience in exchange for not having to modify all the files either by editing them manually or by adding a whole additional new piece of script code (although your password will stay hidden as you type it).
Code:@echo off set d=F:\Backup\My Tasks chcp 65001>nul set "u=%computername%\%username%" set "psCommand=powershell -Command "$password = read-host 'Please enter the run as password for %u%' -AsSecureString ; ^ $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password); ^ [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p for /f "usebackq delims=|" %%f in (`dir /b "\\?\%d%"`) do ( schtasks /create /tn "%%~f" /ru "%u%" /rp "%password%" /xml "\\?\%d%\%%~f" ) del "\\?\%d%\*.*"
I don't care. I've told the OP what I do. What the OP decides to do is up to the OP. So please stop trying to treat this as a discussion between you & me and start addressing the OP in your posts instead.
Denis
Care to explain how this remark of yours addresses the OP?
...which, although I don't doubt that it works, isn't a workable solution to the OP, as the OP clearly stated having "a ton of scheduled tasks to move".I've told the OP what I do.
Where do you see me claim the opposite? Again, care to explain how this remark of yours addresses the OP?What the OP decides to do is up to the OP.
Just because I have quoted a few parts of what you wrote, doesn't also mean that I am treating this as a discussion. I have merely tried to provide a workable solution to the problem described in the OP, which is to reduce the amount of time and effort needed specifically when there are a very large number of tasks to export/import. Thanks, and, have a nice day!So please stop trying to treat this as a discussion between you & me and start addressing the OP in your posts instead.