Scheduling Tasks In Windows – GUI, PowerShell & Command Prompt

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.

how to use task schedulers in Windows
Task Scheduler Window

There are multiple methods using which you can create task schedules:

  • Graphical User Interface (GUI)
  • PowerShell
  • Command Prompt

Lets explore each option in detail for better understanding:

Scheduling Tasks In WindowsGraphical 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.

scheduled tasks PowerShell
Create a New Folder

Step 3 Enter the name of the New folder and click on the “OK” button.

scheduled tasks windows powershell
Name The Folder

Step 4 Navigate the following: Task Scheduler Library > New Folder, then click on “Create Task“.

scheduled tasks command prompt
Create A New 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.

windows task scheduler powershell
General Tab

Step 6 Under the “Triggers” tab, click on the “New” button.

scheduled tasks triggers

Step 7
 Select the trigger when you want to execute an event or task.

windows task schedulers define a trigger
Define Triggers

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.

actions tab in task scheduler

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

scheduling a script in windows task schedulers
Defile Program To Run

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

Start-Process notepad

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.

Source: Microsoft

You’ll Also Like:

Leave a Comment