How to Schedule Tasks with Windows Task Scheduler

Windows Task Scheduler automates running scripts and programs on a defined schedule — the Windows equivalent of cron on Linux, essential for backups, maintenance scripts, and recurring automation.

Creating a Scheduled Task via PowerShell

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\backup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00"
Register-ScheduledTask -TaskName "DailyBackup" -Action $action -Trigger $trigger -RunLevel Highest

Creates a task running a PowerShell script daily at 2:00 AM — -RunLevel Highest runs with elevated (administrator) privileges.

Creating a Task via the Graphical Task Scheduler

taskschd.msc

Opens the graphical interface — useful for less frequent, one-off task creation or when you prefer a visual configuration experience over PowerShell.

Common Trigger Types

# Daily
New-ScheduledTaskTrigger -Daily -At "03:00"

# Weekly, specific days
New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday,Wednesday,Friday -At "09:00"

# At system startup
New-ScheduledTaskTrigger -AtStartup

# Repeating throughout the day
New-ScheduledTaskTrigger -Once -At "00:00" -RepetitionInterval (New-TimeSpan -Hours 1)

Running a Task as a Specific User Account

$principal = New-ScheduledTaskPrincipal -UserId "DOMAIN\serviceaccount" -LogonType Password
Register-ScheduledTask -TaskName "MyTask" -Action $action -Trigger $trigger -Principal $principal

Useful when a task needs to run under a specific service account's context/permissions rather than the default system account.

Viewing Existing Scheduled Tasks

Get-ScheduledTask

Checking a Task's Execution History

Get-ScheduledTaskInfo -TaskName "DailyBackup"

Shows last run time, next scheduled run, and last result code — a non-zero result often indicates the task encountered an error.

Manually Running a Task (For Testing)

Start-ScheduledTask -TaskName "DailyBackup"

Disabling or Removing a Task

Disable-ScheduledTask -TaskName "DailyBackup"
Unregister-ScheduledTask -TaskName "DailyBackup" -Confirm:$false

Configuring Additional Task Settings

$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -DontStopOnIdleEnd
Set-ScheduledTask -TaskName "DailyBackup" -Settings $settings

-StartWhenAvailable runs a missed task as soon as possible if the server was off/asleep at the scheduled time, similar in spirit to systemd's Persistent option on Linux.

Logging Task Output

$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\backup.ps1 >> C:\Logs\backup.log 2>&1"

Redirect script output to a log file for later review, since Task Scheduler itself doesn't automatically capture detailed script output beyond basic result codes.

Common Errors

Task shows as completed but nothing actually happened — check the task's last result code (0x0 typically means success); a non-zero code indicates an error, and reviewing your script's own logging is the most direct path to understanding what went wrong.

Continue Reading

Browse more articles in Windows Server Administration.

  • windows task scheduler, scheduled task powershell, windows cron equivalent, register-scheduledtask
  • 0 کاربر این را مفید یافتند
آیا این پاسخ به شما کمک کرد؟

مقالات مربوطه

How to Connect to a Windows VPS via Remote Desktop (RDP)

Remote Desktop Protocol (RDP) provides full graphical access to a Windows Server VPS, letting you...

How to Secure RDP on a Windows VPS

RDP's default configuration (standard port, password authentication, unlimited login attempts)...

How to Create a New Administrator User on Windows Server

Using only the built-in Administrator account for all management tasks is risky. Creating a...

How to Install Windows Updates on a Windows VPS

Keeping Windows Server updated is essential for security and stability. This guide covers...

How to Configure Windows Firewall on a Windows VPS

Windows Defender Firewall controls which network connections are allowed to and from your server....