- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a Scheduled task with a task scheduler using PowerShell?
To create a task using GUI (As shown below image) we need a few settings like the Name of the task, trigger, and Action.
Similarly, to create a new task in task scheduler using PowerShell comprises of several settings.
- Name of the task
- The time when the task to trigger
- Action − Do we need to schedule a program for execution or send an email on some event trigger.
- Description − This is optional. You can add a description of the task.
- Registering task − Final step is to register the created task.
Above all actions use different cmdlets but they are part of a ScheduledTasks module. To schedule task on local or remote servers, you need to ensure the module should be present on the server.
Get-Module ScheduledTasks | Select -ExpandProperty ExportedCommands
Let's begin creating a task.
- Creating a new Task Action.
$tsaction = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument 'C:\Temp\TestTask.ps1'
- Mention the user account to run the script (optional).
$User= "NT AUTHORITY\SYSTEM"
- Creating a time to trigger a task.
$tstrigger = New-ScheduledTaskTrigger -At 4:00PM -Once
You can provide the various timing for a routine task like Daily, monthly, or other as shown in the below example. In this example, we need to run a task once at 4:00 PM.
- Register Schedule task.
Once the required settings are configured for a task, we need to register the task at the final step to appear in the task scheduler using the below command line.
Register-ScheduledTask ` -TaskName 'Test Task' ` -User $User ` -Action $tsaction ` -Trigger $tstrigger ` -RunLevel Highest -Force
Final Script:
$tsaction = New-ScheduledTaskAction -Execute 'PowerShell.exe' -Argument 'C:\Temp\TestTask.ps1'$User= "NT AUTHORITY\SYSTEM"$tstrigger = New-ScheduledTaskTrigger -At 4:00PM -Once
Output
Register-ScheduledTask ` -TaskName 'Test Task' `-User $User `
-Action $tsaction `
-Trigger $tstrigger `
-RunLevel Highest -Force
Once you run the above command, task will be created. Output will be as shown in the console.
You can check the same in the task scheduler.
- Related Articles
- How to start the specific task of the task scheduler using PowerShell?
- How to retrieve tasks in Task scheduler using PowerShell?
- Task Scheduler n C++
- How to display completion progress of a task in HTML5?
- Different ways to start a Task in C#
- Schedule a task for execution in Java
- How to repeat a task repeatedly after a regular interval in Swift(iOS)?
- How to execute a task repeatedly after fixed time intervals in iOS
- Data parallelism vs Task parallelism
- PEAS Descriptors of Task Environment
- Cancel the Timer Task in Java
- Windows 8 task managers running process
- Schedule a task for execution in Java after a given delay
- Schedule a task for repeated fixed delay execution in Java
- How to execute an Async task repeatedly after fixed time intervals in Android using Kotlin?
