1 minute read

Sometimes, we need to run daily task or schedule a process to run on a window server. This can be tedious and time consuming. So, it’s better to find a way to automate these boring and repeated task for us. One of the ways that can help us to delegate these responsibilies is to use the task scheduler on windows.

Find the Task Scheduler in windows.

task-scheduler

Create Task Scheduler Folder

create-folder

Right click > Create Basic Task

basic-task

Enter Name of the task that we want to automate

task-name

Choose Task trigger

task-trigger

Daily Occurrence setting

daily-task

Action Task

action-task

Start Program

Notes: Here we can start any program and pass the arguments to our target program. The program can be anything. For instance, we can start powershell to run a simple echo command. We use python, nodejs, cmd.exe, etc.

start-program

Task scheduler List

last-step

Once all of daily tasks are set up, we will see the list populated and there are few options for us to check.

list-task

Right click on the task > properties. We need to adjust a few options to make sure the task run smoothly without interruption.

properties

General tab setting

general-tab

To change from running program from once per day to hourly. We can do the following:

hourly-task

Real-life example

The following is the real-life examples that I have set up to run a task in my workplace. First I created a powershell script to trigger an API endpoint to validate all the records in the database.

$token = <JWT TOKEN>
$url = "https://fr-sud.ochca.com/api/provider/maintenance?code=<SECRET CODE>"
 
$headers = @{
    Authorization = "Bearer $token"
}
 
$response = Invoke-WebRequest -Uri $url -Headers $headers -Method Post -Body ''

Write-Output $response

Then, I stored it as a script on the window server to prepare for the daily task.

example-1

Modify the task to add arguments to trigger the powershell script

last-step

And there we go. Now, we have learned to automate our daily task with ease on a windows server.