Managing Task Scheduler with schtasks.exe

Overview

This article explains how to manage the Windows Task Scheduler by using the command-line tool schtasks.exe, which is available by default on Windows Server and Windows client systems.

All examples assume execution from PowerShell, and line continuation is consistently written with the backtick (`) character.


Variable notation

Variable name Example Description
<<SERVER_NAME>> WSRV2025 Target server name
<<ADMIN_USER>> Administrator Execution account
<<TASK_NAME>> DailyTempCleanup Task name
<<SCRIPT_PATH>> C:\Maintenance\cleanup_temp.ps1 Script to execute
<<LOG_PATH>> C:\Maintenance\Logs Log folder
<<BACKUP_PATH>> C:\Maintenance\Backups Event log backup destination

Line continuation in PowerShell vs CMD

All commands in this article are designed to be run from PowerShell.

  • PowerShell: backtick (`)
  • CMD: caret (^)

Example (for PowerShell):

schtasks.exe /Create `
  /TN "Example" `
  /SC DAILY `
  /ST 02:00 `
  /TR "powershell.exe -File example.ps1"

Step 1: schtasks.exe subcommand overview

Subcommand Purpose
/Create Create a new task
/Delete Delete a task
/Query List tasks, show details, export XML
/Change Change task settings
/Run Run a task immediately
/End Stop a running task
/ShowSid Show the SID of the run-as account

Step 2: /Create – basic syntax and main options

Step 2.1 Overall syntax

schtasks.exe /Create `
  /TN "<<TASK_NAME>>" `
  /TR "<<COMMAND_TO_RUN>>" `
  /SC schedule `
  [other options...]

Step 2.2 Commonly used options

Option Description
/SC Schedule type (DAILY / WEEKLY / MONTHLY / ONLOGON / ONEVENT)
/MO Modifier (interval or position)
/ST HH:mm Start time
/D Run day (1–31 or MON/TUE…)
/RU Run-as user
/RP Password (* for interactive input)
/RL HIGHEST Run with highest privileges
/F Force overwrite of existing task

About /MO (modifier)
Parameter that refines the frequency or position of the schedule.

Examples:

  • “Every 3 hours” → /SC HOURLY /MO 3
  • “Every 2 weeks” → /SC WEEKLY /MO 2
  • “Second Wednesday of every month” → /SC MONTHLY /MO SECOND /D WED
  • “Event-triggered task” → /SC ONEVENT /MO [XPath]

Step 2.3 Available /SC schedule types

/SC Description
DAILY Every day
WEEKLY Every week
MONTHLY Every month
ONCE One-time execution
ONSTART At system startup
ONLOGON At user logon
ONIDLE When the system is idle
ONEVENT On event log trigger

Step 2.4 Daily task

schtasks.exe /Create `
  /TN "DailyTempCleanup" `
  /TR "powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Maintenance\cleanup_temp.ps1 -DaysToKeep 7 -LogPath <<LOG_PATH>>" `
  /SC DAILY `
  /ST 02:00 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.5 Run at logon (ONLOGON)

schtasks.exe /Create `
  /TN "OnLogonAudit" `
  /SC ONLOGON `
  /TR "powershell.exe -File C:\Scripts\logon_audit.ps1" `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.6 Run at startup (ONSTART)

schtasks.exe /Create `
  /TN "OnStartInit" `
  /SC ONSTART `
  /TR "powershell.exe -File C:\Scripts\startup_init.ps1" `
  /RU "SYSTEM" `
  /RL HIGHEST `
  /F

Step 2.7 Event log trigger (ONEVENT)

schtasks.exe /Create `
  /TN "Event101Handler" `
  /SC ONEVENT `
  /EC System `
  /MO "*[System/EventID=101]" `
  /TR "powershell.exe -File C:\Scripts\event_handler.ps1" `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.8 Run every 3 hours

schtasks.exe /Create `
  /TN "Every3Hours" `
  /TR "powershell.exe -File script.ps1" `
  /SC HOURLY `
  /MO 3 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.9 Run on the second Wednesday of every month

schtasks.exe /Create `
  /TN "SecondWednesdayTask" `
  /TR "powershell.exe -File task.ps1" `
  /SC MONTHLY `
  /MO SECOND `
  /D WED `
  /ST 03:00 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.10 Run on the last day of each month (LASTDAY)

schtasks.exe /Create `
  /TN "LastDayMonthly" `
  /TR "powershell.exe -File script.ps1" `
  /SC MONTHLY `
  /MO LASTDAY `
  /M * `
  /ST 01:00 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 2.11 Run every 2 weeks

schtasks.exe /Create `
  /TN "Every2Weeks" `
  /TR "powershell.exe -File script.ps1" `
  /SC WEEKLY `
  /MO 2 `
  /D MON `
  /ST 05:00 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Step 3: /Query – list and detail view

Option Description
/FO TABLE Output as a table
/FO LIST Output as key-value list
/V Include detailed information (triggers, actions, etc.)
/TN "<<TASK_NAME>>" Show only the specified task
schtasks.exe /Query /FO TABLE
schtasks.exe /Query /FO LIST /V
schtasks.exe /Query /TN "<<TASK_NAME>>" /FO LIST /V

Step 4: /Change – modify an existing task

Option Description
/TN Target task name
/RU Change run-as user
/RP * Enter new password interactively
/TR Replace the command to be executed
/ENABLE /DISABLE Enable / disable the task

Note: /Change cannot change trigger definitions such as /SC, /MO, /D, /M.
If you need to change the schedule itself, it is safer to /Delete the task and recreate it with /Create.

Change run-as user

schtasks.exe /Change `
  /TN "<<TASK_NAME>>" `
  /RU "<<ADMIN_USER>>" `
  /RP *

Change the command

schtasks.exe /Change `
  /TN "<<TASK_NAME>>" `
  /TR "powershell.exe -File <<SCRIPT_PATH>> -LogPath <<LOG_PATH>>"

Enable / disable a task

schtasks.exe /Change /TN "<<TASK_NAME>>" /ENABLE
schtasks.exe /Change /TN "<<TASK_NAME>>" /DISABLE

Step 5: /Run (run now) and /End (stop)

Option Description
/Run Run the task immediately
/I Ignore schedule constraints (start/end date)
/End Stop a running task
/TN Target task name
schtasks.exe /Run /TN "<<TASK_NAME>>"
schtasks.exe /Run /TN "<<TASK_NAME>>" /I

schtasks.exe /End /TN "<<TASK_NAME>>"

Step 6: Import a task from XML

XML import

Option Description
/XML file Create a task from an XML definition
/RU Override the run-as account
/RP * Enter the password interactively
schtasks.exe /Create `
  /TN "<<TASK_NAME>>" `
  /XML "C:\TaskTemplates\<<TASK_NAME>>.xml" `
  /RU "<<ADMIN_USER>>" `
  /RP *

XML export (via /Query)

Option Description
/XML ONE Export the task definition as a single XML block
> file Redirect the output to a file
schtasks.exe /Query `
  /TN "<<TASK_NAME>>" `
  /XML ONE `
  > C:\TaskTemplates\<<TASK_NAME>>.xml

Step 8: /Delete – remove a task

Option Description
/Delete Delete mode
/TN Target task name
/F Force delete without prompting
schtasks.exe /Delete /TN "<<TASK_NAME>>" /F

Step 9: /ShowSid – display the SID

Option Description
/ShowSid Show the SID associated with the run-as user
/TN Target task name
schtasks.exe /ShowSid /TN "<<TASK_NAME>>"

Step 10: Managing tasks on remote servers

Option Description
/S "<<SERVER_NAME>>" Remote server name
/U User for the remote connection
/P * Password for the remote user (* for interactive input)
Others Same task definition options as for local tasks
schtasks.exe /Create `
  /S "<<SERVER_NAME>>" `
  /U "<<ADMIN_USER>>" `
  /P * `
  /TN "<<TASK_NAME>>" `
  /TR "powershell.exe -File <<SCRIPT_PATH>>" `
  /SC DAILY `
  /ST 02:00 `
  /RU "<<ADMIN_USER>>" `
  /RL HIGHEST `
  /F

Conclusion

By using schtasks.exe, you can tightly integrate Task Scheduler into server build procedures and automation workflows.

  • Combining /SC and /MO allows you to express flexible schedules (daily, weekly, monthly, nth weekday, last day of month, and more).
  • Triggers such as ONLOGON, ONSTART and ONEVENT enable event-driven automation (logon, startup, log events).
  • With /Query /XML and /Create /XML, you can export and re-import task definitions as reusable XML templates.
  • The /Change, /Run, /End, /Delete and /ShowSid subcommands cover the main life-cycle operations for scheduled tasks.
  • By adding /S /U /P, you can roll out identical task definitions to multiple remote servers, supporting large-scale automation scenarios.