Create a scheduled task from CMD with schtasks

Register a recurring Windows task entirely from the command line — ideal for scripts, cleanup jobs, and monitoring probes you want to run unattended.

WindowsProcessessystemTerminalMedium risk
Run `schtasks /Create /TN "Name" /TR "command" /SC WEEKLY /D SUN /ST 02:00` to register a weekly task, and delete it later with `schtasks /Delete /TN "Name" /F`.

01Command

Command
$ schtasks /Create /TN "WeeklyDiskCleanup" /TR "cleanmgr /sagerun:1" /SC WEEKLY /D SUN /ST 02:00

02What it does

The /TN switch is the unique task name (use a folder prefix like `MyCompany\Backup` to group tasks), /TR is the exact command line, and /SC sets the schedule: MINUTE, HOURLY, DAILY, WEEKLY, ONSTART, ONLOGON, and more. Add `/RU SYSTEM` to run as Local System or `/RU domain\user /RP password` for a specific account. Verify with `schtasks /Query /TN "Name" /V` or the Task Scheduler GUI, and test the payload with `schtasks /Run /TN "Name"`. If the task writes files, give it an absolute working directory or it will default to system32.

03Risk

RiskMedium risk
RequirementsRun as administrator for most system-level tasks; the /TR path must be quoted if it contains spaces.
!Warning: Tasks created without /RL or elevated accounts may silently fail on permission errors; check Last Run Result in `schtasks /Query /V` rather than assuming it ran.

04Undo

Undo
$ schtasks /Delete /TN "WeeklyDiskCleanup" /F

05Sources

  • schtasks | Microsoft Learn
    Microsoft · vendor-doc · 2026-09-17
    Evidence: Microsoft documents schtasks /Create with the /TN, /TR, /SC, /D and /ST parameters for scheduling commands to run at a specified time and interval.
  • Schedule tasks - schtasks - Windows CMD
    SS64 · technical · 2026-09-17
    Evidence: SS64 lists schtasks schedules including MINUTE, HOURLY, DAILY, WEEKLY and ONLOGON with syntax examples for each.

Last verified: 2026-09-17 · Category: System & Settings

06Related solutions