Windows Task Scheduler
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.
Create Task Scheduler Folder
Right click > Create Basic Task
Enter Name of the task that we want to automate
Choose Task trigger
Daily Occurrence setting
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.
Task scheduler List
Once all of daily tasks are set up, we will see the list populated and there are few options for us to check.
Right click on the task > properties. We need to adjust a few options to make sure the task run smoothly without interruption.
General tab setting
To change from running program from once per day to hourly. We can do the following:
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.
Modify the task to add arguments to trigger the powershell script
And there we go. Now, we have learned to automate our daily task with ease on a windows server.