Task scheduler – create new task in PowerShell

Task scheduler – create new task in PowerShell

Today, I would like to discuss the topic of creating new tasks in the Windows Task Scheduler, which involves scheduling the execution of specific scripts or programs at a designated time or under certain conditions. In this article, I will demonstrate how to create new tasks in the scheduler using PowerShell, covering both basic and advanced versions. I will also show how to set key task parameters such as trigger, action.

A basic task in the Windows Task Scheduler has only one trigger and one action. The trigger is a condition that initiates the task, such as a specific date and time, a system event, or a user logon. The action is the task’s operation, such as running a PowerShell script, a program, or a document.

To create a task in the Windows Task Scheduler using PowerShell, we can utilize the New-ScheduledTask cmdlet. This cmdlet takes ScheduledTaskTrigger and ScheduledTaskAction objects as parameters, representing the task’s trigger and action, respectively. For example, to create a task that runs a PowerShell script named Test.ps1 every day at 10:00 AM, the following code can be used:

If we want to create a more advanced task, then depending on what we want to achieve, we need to add, for example, additional action options or triggers.

You can also create a task that launches a program or script upon user logon by utilizing the -AtLogon parameter.

To remove a task from the scheduler, simply execute the command:

Komentarze

Nie ma jeszcze komentarzy. Może zaczniesz dyskusję?

Dodaj komentarz

Twój adres e-mail nie zostanie opublikowany. Wymagane pola są oznaczone *