Skip to content

Managing Task Scheduler with schtasks.exe

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 nameExampleDescription
<<SERVER_NAME>>WSRV2025Target server name
<<ADMIN_USER>>AdministratorExecution account
<<TASK_NAME>>DailyTempCleanupTask name
<<SCRIPT_PATH>>C:\Maintenance\cleanup_temp.ps1Script to execute
<<LOG_PATH>>C:\Maintenance\LogsLog folder
<<BACKUP_PATH>>C:\Maintenance\BackupsEvent log backup destination

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

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

Example (for PowerShell):

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

The Microsoft-Windows-TaskScheduler/Operational channel may be disabled by default.
Enable it for troubleshooting and detailed history:

Terminal window
wevtutil sl Microsoft-Windows-TaskScheduler/Operational /e:true

SubcommandPurpose
/CreateCreate a new task
/DeleteDelete a task
/QueryList tasks, show details, export XML
/ChangeChange task settings
/RunRun a task immediately
/EndStop a running task
/ShowSidShow the SID of the run-as account

Step 2: /Create – basic syntax and main options

Section titled “Step 2: /Create – basic syntax and main options”
Terminal window
schtasks.exe /Create `
/TN "<<TASK_NAME>>" `
/TR "<<COMMAND_TO_RUN>>" `
/SC schedule `
[other options...]
OptionDescription
/SCSchedule type (DAILY / WEEKLY / MONTHLY / ONLOGON / ONEVENT)
/MOModifier (interval or position)
/ST HH:mmStart time
/DRun day (1–31 or MON/TUE…)
/RURun-as user
/RPPassword (* for interactive input)
/RL HIGHESTRun with highest privileges
/FForce 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]
/SCDescription
DAILYEvery day
WEEKLYEvery week
MONTHLYEvery month
ONCEOne-time execution
ONSTARTAt system startup
ONLOGONAt user logon
ONIDLEWhen the system is idle
ONEVENTOn event log trigger

Terminal window
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

Terminal window
schtasks.exe /Create `
/TN "OnLogonAudit" `
/SC ONLOGON `
/TR "powershell.exe -File C:\Scripts\logon_audit.ps1" `
/RU "<<ADMIN_USER>>" `
/RL HIGHEST `
/F
Terminal window
schtasks.exe /Create `
/TN "OnStartInit" `
/SC ONSTART `
/TR "powershell.exe -File C:\Scripts\startup_init.ps1" `
/RU "SYSTEM" `
/RL HIGHEST `
/F
Terminal window
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

Terminal window
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

Section titled “Step 2.9 Run on the second Wednesday of every month”
Terminal window
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)

Section titled “Step 2.10 Run on the last day of each month (LASTDAY)”
Terminal window
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

Terminal window
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

OptionDescription
/FO TABLEOutput as a table
/FO LISTOutput as key-value list
/VInclude detailed information (triggers, actions, etc.)
/TN "<<TASK_NAME>>"Show only the specified task
Terminal window
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

Section titled “Step 4: /Change – modify an existing task”
OptionDescription
/TNTarget task name
/RUChange run-as user
/RP *Enter new password interactively
/TRReplace the command to be executed
/ENABLE /DISABLEEnable / 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.

Terminal window
schtasks.exe /Change `
/TN "<<TASK_NAME>>" `
/RU "<<ADMIN_USER>>" `
/RP *
Terminal window
schtasks.exe /Change `
/TN "<<TASK_NAME>>" `
/TR "powershell.exe -File <<SCRIPT_PATH>> -LogPath <<LOG_PATH>>"
Terminal window
schtasks.exe /Change /TN "<<TASK_NAME>>" /ENABLE
schtasks.exe /Change /TN "<<TASK_NAME>>" /DISABLE

OptionDescription
/RunRun the task immediately
/IIgnore schedule constraints (start/end date)
/EndStop a running task
/TNTarget task name
Terminal window
schtasks.exe /Run /TN "<<TASK_NAME>>"
schtasks.exe /Run /TN "<<TASK_NAME>>" /I
schtasks.exe /End /TN "<<TASK_NAME>>"

OptionDescription
/XML fileCreate a task from an XML definition
/RUOverride the run-as account
/RP *Enter the password interactively
Terminal window
schtasks.exe /Create `
/TN "<<TASK_NAME>>" `
/XML "C:\TaskTemplates\<<TASK_NAME>>.xml" `
/RU "<<ADMIN_USER>>" `
/RP *
OptionDescription
/XML ONEExport the task definition as a single XML block
> fileRedirect the output to a file
Terminal window
schtasks.exe /Query `
/TN "<<TASK_NAME>>" `
/XML ONE `
> C:\TaskTemplates\<<TASK_NAME>>.xml

OptionDescription
/DeleteDelete mode
/TNTarget task name
/FForce delete without prompting
Terminal window
schtasks.exe /Delete /TN "<<TASK_NAME>>" /F

OptionDescription
/ShowSidShow the SID associated with the run-as user
/TNTarget task name
Terminal window
schtasks.exe /ShowSid /TN "<<TASK_NAME>>"

OptionDescription
/S "<<SERVER_NAME>>"Remote server name
/UUser for the remote connection
/P *Password for the remote user (* for interactive input)
OthersSame task definition options as for local tasks
Terminal window
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

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.