任务计划程序(Task Scheduler)是一种工具,可让您在Windows 11/10计算机上创建和自动化日常任务。( create and automate routine tasks)本机工具主要用于运行任何监控工具,以及进行磁盘碎片整理、磁盘清理和安装 Windows 更新(install Windows updates)等维护任务。在这篇文章中,我们将向您展示在Windows 11/10任务计划程序(Task Scheduler)导入或导出任务的方法。
任务计划程序(Task Scheduler)还可用于执行任务,例如启动应用程序、发送电子邮件、运行命令、在特定日期和时间执行脚本或显示消息框。
(Task Scheduler)可以安排任务计划程序以响应以下事件或触发器:
- 在特定时间。
- 在每日计划的特定时间。
- 在每周计划的特定时间。
- 在每月计划的特定时间。
- 系统启动时。
- 当计算机进入空闲状态时。
- 当用户登录时。
- 注册任务时。
您可以根据上述响应创建任务和计划。
任务也可以保存,如果需要,您可以将任务从一台计算机导入或导出到另一台计算机。
从任务计划程序(Task Scheduler)导入或导出任务(Export Tasks)
您可以通过以下三种方法之一从Windows 11/10中的任务计划程序(Task Scheduler)导入或导出计划任务:
- 使用任务计划程序
- 使用命令提示符
- 使用 PowerShell
让我们看一下与列出的每个方法相关的步骤。
1]使用任务计划程序
这种使用任务计划(Task Scheduler)程序在Windows 10中导入或导出计划任务(Tasks)的方法是最简单的。
出口
要导出,请执行以下操作:
- 按Windows key + R调用“运行”对话框。
- 在“运行”对话框中,键入taskschd.msc
- 按CTRL+SHIFT+ENTER组合键以管理员模式打开任务计划程序。(open Task Scheduler)
- 单击以展开左侧窗格中的任务计划程序库。(Task Scheduler Library)
- 在中间窗格中,右键单击任务(Task)并选择导出。( Export.)
- 选择保存文件的位置。
- 单击保存(Save) 按钮。
保存后,您可以在该特定保存位置找到XML文件。(XML)您可以使用USB驱动器将此XML文件复制到另一台计算机,也可以通过电子邮件发送该文件。
进口
要导入,请执行以下操作:
在导入之前,请确保您已经复制了运行任务所需的所有文件。例如,如果您要运行任何PowerShell脚本,请确保您已将脚本与XML文件一起复制。
导出任务(Tasks)仅导出任务计划程序(Task Scheduler)任务配置。它不会复制所需的文件。所以复制所有需要的文件,然后开始导入。
- 在管理模式下打开 任务计划程序。( Task Scheduler)
- 单击以展开左侧窗格中的任务计划程序库。(Task Scheduler Library)
- 右键单击(Right-click)任务的文件夹,然后选择导入任务。( Import Task.)
- 现在,浏览XML 文件(XML file) 位置并单击 Open。
如果您已经配置了任何任务(Task)设置,请在导入后进行。
2]使用命令提示符
要使用命令提示符(Command Prompt)在Windows 10中导入或导出计划任务(Tasks),您需要使用 Schtasks.exe命令。此命令使用户能够在本地或远程计算机上创建、删除、查询、更改、运行和结束计划任务。
出口
要导出,请执行以下操作:
- 按Windows key + R。调用“运行”对话框。
- 在“运行”对话框中,键入cmd,然后按CTRL + SHIFT + ENTER以open Command Prompt in admin/elevated mode。
- 在命令提示符窗口中,复制并粘贴下面的命令,然后按 Enter(Enter)。
- 将task_location和task_name占位符替换为来自(task_name )任务计划程序(Task Scheduler)的任务的实际位置和名称。
- 如果单击中间窗格中的任务(Task),您可以找到任务的位置和名称。(Task)
- 将%UserProfile% 替换为您的完整配置文件路径。例如C:\Users\Chidum.Osobalu。
schtasks /Query /XML /TN “task_location\task_name” > “%UserProfile%\Desktop\Export Tasks\name.xml”
执行命令后,确保文件位于您在命令中提到的正确位置。
进口
要导入,请执行以下操作:
命令提示符中没有导入选项。因此,您可以使用导出的同一个XML文件创建一个新任务,而不是导入和设置位置和脚本。(XML)
在管理员/提升模式下打开命令提示符。(Command Prompt)
在CMD窗口中,复制并粘贴下面的命令,然后按 Enter(Enter)。
schtasks /create /xml “%UserProfile%\XML file Path\TaskName.xml” /tn “\TASKSCHEDULER-FOLDER-PATH\TASK- NAME” /ru “COMPUTER-NAME\USER-NAME” /rp SystemPassword
替换(Replace)命令中的以下占位符:
“%UserProfile%\XML file Path\TaskName.xml – 复制导出的 XML 文件路径。
TASKSCHEDULER-FOLDER-PATH –将(Replace)其替换为任务计划程序(Task Scheduler)中任务的(Task)任务(Task)位置路径。
TASK- NAME – 你可以给任何名字。
COMPUTER-NAME - 您的系统主机名(Hostname)。要从系统中获取主机名,请在 CMD 提示符下键入主机名并按 Enter。(hostname)
USER-NAME – 您的系统用户名。
SystemPassword –输入(Input)您的系统密码(如果您已设置)。
3]使用PowerShell
要使用PowerShell在Windows 10中导入或导出计划任务(Tasks),您需要使用Export-ScheduledTask cmdlet。
出口
要导出,请执行以下操作:
按Windows key + X访问高级用户菜单。
点击键盘上的A以在管理员/提升模式下启动 PowerShell 。
在PowerShell控制台中,复制并粘贴下面的命令,然后按 Enter(Enter)。
Export-ScheduledTask -TaskName “task location from scheduler\task name” > “$env:UserProfile\Desktop\name.xml”
替换(Replace)命令中的以下占位符:
执行命令后,任务将导出到指定位置。
进口
要导入,请执行以下操作:
在这里,就像在命令提示符中一样, (Command Prompt)PowerShell中也没有导入命令。因此,您需要使用Register 命令(Register command)使用导出的XML文件创建新任务。
以管理员模式打开 PowerShell。
在PowerShell窗口中,复制并粘贴以下命令,并根据您的要求稍作修改。
Register-ScheduledTask -xml (Get-Content ‘C:\PASTE THE PATH OF THE EXPORTED XML FILE WITH NAME.XML ‘ | Out-String) -TaskName “TASK-IMPORT-NAME” -TaskPath “\TASK-PATH-TASKSCHEDULER\” -User COMPUTER-NAME\USER-NAME –Password TYPE YOUR PASSWORD -Force
确保(Make)相应地替换所有大写占位符并执行命令。执行命令后,导出的任务调度器将在任务调度器中创建为新任务(Task Scheduler)。
The above are the 3 ways you can import or export Tasks from Task Scheduler in Windows 11/10.
How to Import or Export Tasks from Task Scheduler in Windows 11/10
Task Scheduler is a tool that allows you to create and automate routine tasks on a Windows 11/10 computer. The native tool is mainly used to run any monitoring tools, and for maintenance tasks such as disk defragmentation, disk cleanup, and install Windows updates. In this post, we will show you the ways in which you can import or export Tasks from Task Scheduler in Windows 11/10.
Task Scheduler can also be used to execute tasks such as starting an application, sending an email message, run commands, executing scripts at a particular day and time, or showing a message box.
Task Scheduler can be scheduled in response to the following events or triggers:
- At a specific time.
- At a specific time on a daily schedule.
- At a specific time on a weekly schedule.
- At a specific time on a monthly schedule.
- When the system is booted.
- When the computer enters an idle state.
- When a user logs on.
- When the task is registered.
You can create tasks and schedules based on the above response.
Tasks can be saved as well and if you want, you can import or export the task from one computer to another.
Import or Export Tasks from Task Scheduler
You can import or export scheduled tasks from the Task Scheduler in Windows 11/10 in any of the three following methods:
- Using Task Scheduler
- Using Command Prompt
- Using PowerShell
Let’s take a look at the steps involved in relation to each of the listed methods.
1] Using Task Scheduler
This method of using Task Scheduler to import or export scheduled Tasks in Windows 10 is the easiest.
Export
To export, do the following:
- Press Windows key + R to invoke the Run dialog.
- In the Run dialog, type taskschd.msc
- Press CTRL+SHIFT+ENTER key combo to open Task Scheduler in admin mode.
- Click to expand the Task Scheduler Library on the left pane.
- On the middle pane, right-click on the Task and choose Export.
- Choose the location to save the file.
- Click on the Save button.
After saving you can find the XML file in that particular saved location. You can copy this XML file to another machine using a USB drive or you can email the file.
Import
To import, do the following:
Before importing make sure you have copied all the required files to run the tasks. For example, if you are going to run any PowerShell scripts make sure you have copied the script along with the XML file.
Exporting Tasks only export the Task Scheduler task configurations. It won’t copy the required files. So copy all the required files and then start importing.
- Open the Task Scheduler in administrative mode.
- Click to expand the Task Scheduler Library on the left pane.
- Right-click on the folder for the task and choose Import Task.
- Now, browse the XML file location and click on Open.
If you already configured any Task Settings do it after the import.
2] Using Command Prompt
To import or export scheduled Tasks in Windows 10 using Command Prompt, you will need to use the Schtasks.exe command. This command enables users to create, delete, query, change, run, and end scheduled tasks on a local or remote computer.
Export
To export, do the following:
- Press Windows key + R. to invoke the Run dialog.
- In the Run dialog box, type cmd and then press CTRL + SHIFT + ENTER to open Command Prompt in admin/elevated mode.
- In the command prompt window, copy and paste the command below and hit Enter.
- Replace the task_location and task_name placeholder with the actual location and name of the Task from the Task Scheduler.
- You can find the location and name of the Task, if you click on the Task in the middle pane.
- Replace %UserProfile% with your full profile path. Eg C:\Users\Chidum.Osobalu.
schtasks /Query /XML /TN “task_location\task_name” > “%UserProfile%\Desktop\Export Tasks\name.xml”
Once the command is executed make sure the file is located in the correct location which you have mentioned in the command.
Import
To import, do the following:
There is no import option in the command prompt. So, instead of importing and setting the location and script, you can create a new task using the same XML file you exported.
Open Command Prompt in admin/elevated mode.
In the CMD window, copy and paste the command below and hit Enter.
schtasks /create /xml “%UserProfile%\XML file Path\TaskName.xml” /tn “\TASKSCHEDULER-FOLDER-PATH\TASK- NAME” /ru “COMPUTER-NAME\USER-NAME” /rp SystemPassword
Replace the following placeholders in the command:
“%UserProfile%\XML file Path\TaskName.xml – Copy the exported XML file path.
TASKSCHEDULER-FOLDER-PATH – Replace it with the Task location path of the Task in Task Scheduler.
TASK- NAME – You can give any name.
COMPUTER-NAME – Your system Hostname. To get hostname from the system, type hostname in CMD prompt and hit Enter.
USER-NAME – Your system username.
SystemPassword – Input your system password, if you have set one.
3] Using PowerShell
To import or export scheduled Tasks in Windows 10 using PowerShell, you will need to use the Export-ScheduledTask cmdlet.
Export
To export, do the following:
Press Windows key + X to access the Power User Menu.
Tap A on the keyboard to launch PowerShell in admin/elevated mode.
In the PowerShell console, copy and paste the command below and hit Enter.
Export-ScheduledTask -TaskName “task location from scheduler\task name” > “$env:UserProfile\Desktop\name.xml”
Replace the following placeholders in the command:
- Task location from the scheduler
- Task name
- Name.xml
Once you execute the command the task will be exported to the specified location.
Import
To import, do the following:
Here, just like in Command Prompt, there is no import command in PowerShell also. So, you’ll need to use the Register command to create the new task with the exported XML file.
Open PowerShell in admin mode.
In the PowerShell window, copy and paste the command below with slight modification as per your requirement.
Register-ScheduledTask -xml (Get-Content ‘C:\PASTE THE PATH OF THE EXPORTED XML FILE WITH NAME.XML ‘ | Out-String) -TaskName “TASK-IMPORT-NAME” -TaskPath “\TASK-PATH-TASKSCHEDULER\” -User COMPUTER-NAME\USER-NAME –Password TYPE YOUR PASSWORD -Force
Make sure all the caps placeholders are replaced accordingly and execute the command. After the execution of the command, the exported task scheduler will be created as a new task in the Task Scheduler.
The above are the 3 ways you can import or export Tasks from Task Scheduler in Windows 11/10.