Task Scheduler is a component of Microsoft Windows that provides the ability to schedule the launch of programs or scripts at pre-defined times or after specified time intervals: job scheduling. Scheduling Tasks In Windows allows the user to create and run any task or script automatically on any particular date and time or when any certain event occurs. It helps to run the task automatically instead of running manually which reduces the exasperation of the user.
There are multiple methods using which you can create task schedules:
- Graphical User Interface (GUI)
- Command Prompt
Lets explore each option in detail for better understanding:
Scheduling Tasks In Windows – Graphical User Interface (GUI)
Step 1 Open Start, Search for “Task Scheduler” and press enter to open “Task Scheduler”.
Step 2 Right-click on the “Task Scheduler Library” and click on the “New Folder” option.
Step 3 Enter the name of the New folder and click on the “OK” button.
Step 4 Navigate the following: Task Scheduler Library > New Folder, then click on “Create Task“.
Step 5 Under the “General” tab, provide the Task Name such as “Notepad” and in the “Security options” section, you can select which administrator account can run the task. Now here please note that the User account you specify here must have the full access to run the target file/script which you are scheduling, otherwise, the task will be failed.
Step 6 Under the “Triggers” tab, click on the “New” button.
Step 7 Select the trigger when you want to execute an event or task.
For example: Select the “On a schedule” option and then, you can see various options to schedule the task or an event accordingly. Under the “settings” section, first, choose when would you like your task to start and then set the start date and time of the task and under the “Advanced settings” section, you can select options to delay, repeat, stop, and expire a task or an event.
Step 8 Under the “Actions” tab, click on the “New” button.
Step 9 “New Action” window will appear on the screen then, select the “Start a program” option from a various list of actions and click on the “Browse” button and choose the program and click on OK.
For example: choose “notepad.exe” from C\Windows\System32.
Step 10 Under the “Conditions” tab, you can see various options to configure or set the conditions to run the task or an event accordingly. The “Power” section enables users to configure their requirements.
Step 11 Under the “Settings” tab, the user can “specify additional settings that affect the behavior of the task” and then click on the “OK” button.
Creating Scheduled Tasks With PowerShell
Sometimes you need to create a scheduled task on hundred of servers. In that case, the GUI method will take forever. Hence now we will see how can we create the tasks in PowerShell
PowerShell has a CmdLet to deal with Scheduled Tasks: Register-ScheduledTask.
Here is an example of scheduling a PowerShell script to open notepad through Windows Task Scheduler in PowerShell
My PS1 file which I need to schedule: notepad.ps1
Code to Create Scheduled Task In PowerShell:
$trigger = New-ScheduledTaskTrigger -At 10:00AM -Daily
$user = "NT Authority\SYSTEM"
$Action = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument "D:\PowerShell\notepad.ps1"
Register-ScheduledTask -TaskName "Start Notepad Script" -Trigger $trigger -User $user -Action $Action -RunLevel Highest -Force
Note: You can use the CimSession property of Register-ScheduleTask CmdLet to use this on multiple servers remotely.
Creating Scheduled Tasks With Command Prompt
The way we created the scheduled task in PowerShell, similarly we can also create the same task with Command Prompt as well.
Below is the format which we will use to schedule the same PowerShell script through cmd:
SCHTASKS /CREATE /SC DAILY /TN "Start Notepad Script" /TR "D:\PowerShell\notepad.ps1" /ST 10:00
Here /SC is the trigger frequency, /TN is the task name, /TR is the path to the program/script which we need to run, and /ST is the trigger time.
So that was all about the scheduling programs/scrips in Windows Task Schedulers through GUI, PowerShell and CMD. I hope this article would be helpful to you. In case of any queries or feedback, kindly let us know in the comment section.
You’ll Also Like:
- How to expand raid 5 in dell servers using omsa on the fly?
- Microsoft Certified Azure Administrator AZ-104 Free Exam Practice Questions
- Best Way To Blur Text or Image with Microsoft Paint
- Generating And sending HTML reports in Email through PowerShell