Export/Import Scheduled Tasks in bulk

Page 1 of 3 123 LastLast

  1. Posts : 970
    Microsoft Windows 10 Professional (x64) Build 19045.2846
       #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?
      My Computer


  2. Posts : 1,203
    11 Home
       #2

    To copy all the tasks to your folder E:\Backup\My Tasks
    Code:
    @echo off
    set d=E:\Backup\My Tasks
    chcp 65001>nul
    copy \\?\%Windir%\System32\Tasks\*.* "\\?\%d%"
    (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.)

    Next, on the other computer, assuming that your folder to which you have copied the tasks is now F:\Backup\My Tasks
    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%\*.*"
    (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." )
    Last edited by hdmi; 20 Jan 2022 at 08:15.
      My Computers


  3. Posts : 16,948
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #3

    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.
    SchTasks /Create /?
    schtasks - SS64
    schtasks MSDocs
    or I'd examine PowerShell's capabilities in this respect

    Denis
    Last edited by Try3; 19 Jan 2022 at 04:59.
      My Computer


  4. Posts : 1,203
    11 Home
       #4

    @Try3

    With the /xml parameter the schtasks.exe tool conveniently ignores the file extension. It only looks at the content of the file, so renaming the file is not needed.
      My Computers


  5. Posts : 970
    Microsoft Windows 10 Professional (x64) Build 19045.2846
    Thread Starter
       #5

    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?
      My Computer


  6. Posts : 1,203
    11 Home
       #6

    kitpzyxmsir said:
    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...).
      My Computers


  7. Posts : 16,948
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #7

    kitpzyxmsir said:
    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?
    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


    kitpzyxmsir said:
    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?
    As I said above,
    Try3 said:
    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.
    - 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.
      My Computer


  8. Posts : 1,203
    11 Home
       #8

    Try3 said:
    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.
    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%\*.*"
      My Computers


  9. Posts : 16,948
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #9

    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
      My Computer


  10. Posts : 1,203
    11 Home
       #10

    Try3 said:
    I don't care.
    Care to explain how this remark of yours addresses the OP?
    I've told the OP what I do.
    ...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".
    What the OP decides to do is up to the OP.
    Where do you see me claim the opposite? Again, care to explain how this remark of yours addresses the OP?
    So please stop trying to treat this as a discussion between you & me and start addressing the OP in your posts instead.
    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!
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:31.
Find Us




Windows 10 Forums