How to Run a Scheduled Task in Task Scheduler Through PowerShell Command

Rohan Timalsina Feb 02, 2024
How to Run a Scheduled Task in Task Scheduler Through PowerShell Command

Task Scheduler is a program in Windows that allows you to run scheduled tasks automatically on a computer. Tasks are executed whenever certain predefined criteria (triggers) are met.

You can execute tasks like launching an application, sending an e-mail, and running a script at a specific time with the task scheduler. Multiple cmdlets are available in PowerShell to work with scheduled tasks on a computer.

You can enable, disable, view, create, register, start, stop, remove, and unregister scheduled tasks in PowerShell. This tutorial will teach you to start a scheduled task in a task scheduler through the PowerShell command.

Use Start-ScheduledTask Cmdlet to Run a Scheduled Task in Task Scheduler in PowerShell

You can view the task object of a scheduled task registered on the computer using the Get-ScheduledTask cmdlet.

The following command gets all scheduled task definition objects.

Get-ScheduledTask

Output:

gets all scheduled task definition objects

You can use the -TaskName parameter to specify the names of a scheduled task. This command gets the task definition object of a scheduled task named McAfeeLogon.

Get-ScheduledTask -TaskName "McAfeeLogon"

Output:

TaskPath                                       TaskName                          State
--------                                       --------                          -----
\                                              McAfeeLogon                       Ready

The above output shows that a scheduled task is located in the root directory, and its state is currently Ready.

The -TaskPath parameter specifies the path of a scheduled task. The following command displays all task definitions objects in the directory \Microsoft\Office\.

Get-ScheduledTask -TaskPath "\Microsoft\Office\"

Output:

gets scheduled task definitions objects in specific folder

You can start a scheduled task using PowerShell’s Start-ScheduledTask cmdlet. This command starts a registered scheduled task named McAfeeLogon in the root folder.

Start-ScheduledTask -TaskName "McAfeeLogon"

Next, check the state of a scheduled task McAfeeLogon to confirm it is running.

Get-ScheduledTask -TaskName "McAfeeLogon"

Output:

TaskPath                                       TaskName                          State
--------                                       --------                          -----
\                                              McAfeeLogon                       Running

The following command starts all scheduled tasks in the folder \Microsoft\Windows\Shell\.

Get-ScheduledTask -TaskPath "\Microsoft\Windows\Shell\" | Start-ScheduledTask

Now, verify the state of scheduled tasks in the folder \Microsoft\Windows\Shell\.

Get-ScheduledTask -TaskPath "\Microsoft\Windows\Shell\"

Output:

start all tasks in a folder using start-scheduledtask cmdlet

We hope you have understood how to run a scheduled task in the task scheduler using PowerShell. For more information on ScheduledTasks, read this article.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell Task Scheduler