Overview
Windows Scheduled Tasks is a built-in tool in Windows that allows you to automate repetitive tasks on your computer. It allows you to run programs, scripts, or batch files at specific times or when certain events occur. It is a powerful tool that allows you to automate repetitive tasks on your computer. You can use PowerShell scripts or the Command Prompt to manage Windows Scheduled Tasks, including retrieving information about existing tasks, creating new tasks, and scheduling a task.
We will explore the different PowerShell scripts you can use to manage Windows Scheduled Tasks, including how to retrieve information about existing tasks, create new tasks, and schedule a task through PowerShell.
Getting Information about Existing Tasks:
To retrieve information about existing tasks, you can use the following PowerShell cmdlet:
Get-ScheduledTask
This cmdlet retrieves a list of all the scheduled tasks on your computer, including the task name, status, next run time, and more.
Creating a New Task:
To create a new task, you can use the following PowerShell cmdlet:
New-ScheduledTask
This cmdlet creates a new scheduled task with the specified parameters, such as the task name, action, trigger, and more. Here’s an example of how to create a new task that runs a script every day at 3 PM:
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-file C:\Scripts\MyScript.ps1"
$Trigger = New-ScheduledTaskTrigger -Daily -At 3pm
$Settings = New-ScheduledTaskSettingsSet
Register-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -TaskName "MyTask"
Scheduling a Task through PowerShell:
To schedule a task through PowerShell, you can use the Register-ScheduledTask cmdlet. This cmdlet allows you to create a new task or update an existing task with the specified parameters. Here’s an example of how to schedule a task that runs a script every Monday at 9 AM:
$Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-file C:\Scripts\MyScript.ps1"
$Trigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday -At 9am
$Settings = New-ScheduledTaskSettingsSet
Register-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings -TaskName "MyTask"
Ways to manage Windows Scheduled Tasks through Command Prompt:
In addition to using PowerShell, you can also manage Windows Scheduled Tasks through the Command Prompt using the following commands:
schtasks /query
schtasks /create
schtasks /run
The schtasks /query command retrieves information about existing tasks, the schtasks /create command creates a new task, and the schtasks /run command runs a task immediately.