Often when you want to schedule tasks in Windows, you will usually look for the Windows Task Scheduler utility first. However, it is possible to use Windows PowerShell cmdlets to create, edit, and delete scheduled tasks.
But why should you use PowerShell to schedule tasks instead of the designated Tash Scheduler tool? Let’s find out.
Why use PowerShell instead of Task Scheduler?
For most Windows users, it’s easier to use Task Scheduler to create simple scheduled tasks. However, the main reason to use PowerShell instead of Task Scheduler is primarily the ability to create a script that interacts with the system via a scheduled task.
Task Scheduler has been a part of Windows for a long time and you can learn more about how to run programs automatically using Task Scheduler in our guide. This will help you decide the best method of creating scheduled tasks for your specific needs.
What is a PowerShell script?
Windows PowerShell is a task automation and configuration management program. It also includes a scripting language. PowerShell scripts, called “cmdlets,” allow you to create complex multi-action operations.
A PowerShell script could be used for something as simple as collecting and presenting information about a computer. A network administrator could create a script that shuts down all computers on a network that are not being used.
Scripts are most commonly used by system and network administrators, but that doesn’t mean you can’t create PowerShell scripts to perform simple and complex actions on your personal computer. In fact, there are many simple Windows scripts that are easy to set up and yet provide a wealth of features.
Create a scheduled task in PowerShell (elevated)
You will need to open PowerShell with administrator privileges when you want to create scheduled tasks. If you don’t know how to do that, be sure to learn more about starting programs with elevated privileges.
To open PowerShell, right-click the Start menu button and select PowerShell (Admin) from the power user menu. If you don’t see that option, look for Shell Power in Windows Search and select Execute as an administrator.
You must create a variable to hold the action of the task. To do this, type: $action = New-ScheduledTaskAction -Execute ‘PROGRAM‘ and press Get into. Replace PROGRAM with the name of the program you are creating the task for.
The variable name in the above command is the $action part. You can change this to anything you like, but it’s best to keep it short and descriptive. It also has to be in lowercase.
Next, create the trigger for the scheduled task. This will include a repeat time and rate. To add a trigger, type: $trigger = New-ScheduledTaskTrigger –ADJUSTMENT -A WEATHER. Replace -ADJUSTMENT as often as Daily. Replace -At the time with a time, such as “At 7 am”.
You can use Once, Daily, Weekly, or Monthly for the frequency. The time can be in 12 or 24 hour format. If you are using the Weekly frequency, you can also add -Weekdaysand then the day. Tuesday, for instance. you can also use -Interval of days to control the frequency. For example, –3 days intervalwill run the task every three days.
Now you need to put all the information together in one command. In the following command line, replace HOMEWORK FOLDER, NAME OF THE HOMEWORKY OPTIONAL DESCRIPTION TEXT with your homework information. the -Task Route it is optional but helps you identify your created tasks.
To create the scheduled task, type: Register-ScheduledTask -Action $action -Trigger $trigger -TaskPath “HOMEWORK FOLDER” -Name of the homework “NAME OF THE HOMEWORK” -Description “OPTIONAL DESCRIPTION TEXT“. Press Get into.
The scheduled task will be created and fired when the frequency and time triggers are reached.
Modify a scheduled task in PowerShell (elevated)
You can also use PowerShell to modify a previously created scheduled task. You can edit a scheduled task even if it is currently active. You will need to know the name of the scheduled task and the path of the task.
Open PowerShell with administrator privileges by searching Windows Search and clicking Execute as an administrator.
You must create a variable to hold the scheduled task changes. Write: $trigger = New-ScheduledTaskTrigger –ADJUSTMENT –At the time. Change -ADJUSTMENT Y -At the time to the frequency and time you want to set for the task.
To change the program that the scheduled task uses, type: $action = New-ScheduledTaskAction -Execute ‘PROGRAM’. Replace PROGRAM in the command with the name of the program you want to use along with the path to the .exe file.
Then apply those changes to the scheduled task by typing: Set-ScheduledTask -Trigger $trigger -Action $action -TaskPath “HOMEWORK FOLDER” -Name of the homework “NAME OF THE HOMEWORK“. Replace HOMEWORK FOLDER Y NAME OF THE HOMEWORK with details of the task you want to change.
How to kill scheduled tasks in PowerShell
Scheduled tasks created in PowerShell can also be deleted in PowerShell.
Open PowerShell (elevated) and type the following command to confirm that the task exists and is active: Get-ScheduledTask -TaskName “TASK-NAMME”. Replace NAME OF THE HOMEWORK with the name of the task you want to delete.
Assuming the scheduled task is found, you can remove it with the following command: Unregister-ScheduledTask -TaskName “NAME OF THE HOMEWORK” -Confirm:$false. Replace NAME OF THE HOMEWORK with the name of the task you want to delete.
To confirm that the task has been deleted, type: Get-ScheduledTask -TaskName “NAME OF THE HOMEWORK“replacing NAME OF THE HOMEWORK with the name of the scheduled task you deleted.
You should then see a warning that no task with that name exists. If you see details of the queried scheduled task, it was not deleted successfully. Check the details you entered during step 1 above.
Additional PowerShell cmdlets for scheduled tasks
Now that you understand the basics of creating scheduled tasks in PowerShell, you can experiment with other cmdlets.
There are several other ways to control scheduled tasks with command lines. These include temporarily disabling tasks, exporting a scheduled task as an XML string, and stopping all running tasks.
You can find a complete list of all PowerShell scheduled task cmdlets in Microsoft Docs.
Create scheduled tasks in Windows PowerShell
Not everyone will need to use PowerShell to create scheduled tasks. Task Scheduler does a good job of letting you schedule simple tasks, like opening apps. But if you need to know how to create scheduled tasks in PowerShell, Windows’ powerful automation tool, this guide is a great place to start.