Skip to content

How to List All Scheduled Tasks in Batch Script

Learn how to use schtasks /query in batch scripts to list all scheduled tasks, format output as CSV for parsing, and create automated reports with FOR /F loops.

Scheduled tasks are the backbone of Windows automation, running everything from daily backups to system maintenance routines. For administrators and power users, being able to get a complete list of all the tasks scheduled on a machine is a critical part of auditing, troubleshooting, and system inventory. The standard, built-in command-line utility for this is the powerful schtasks.exe.

This guide will teach you how to use the schtasks /query command to list all scheduled tasks. You will learn how to format the output into a script-friendly CSV format and how to parse this list with a FOR /F loop to create powerful, automated reports.

The Core Command: schtasks /query

The schtasks.exe utility's query command is designed to display all the scheduled tasks on a local or remote computer.

Syntax: schtasks /query [options]

When run with no options, it produces a human-readable table of all tasks.

Basic Example: A Simple Task List

Running the command by itself is the quickest way to get a look at the scheduled tasks.

@ECHO OFF
ECHO --- Listing All Scheduled Tasks ---
ECHO.
schtasks /query

The output is a table showing the task name, when it will next run, and its current status.

Folder: \
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
My Daily Backup                          10/28/2023 11:00:00 PM Ready
GoogleUpdateTaskMachineUA                10/28/2023 10:45:12 AM Ready
...

Folder: \Microsoft\Windows\Defrag
TaskName                                 Next Run Time          Status
======================================== ====================== ===============
ScheduledDefrag                          N/A                    Ready
... (and many more) ...

Key /query Parameters Explained

To make the output useful for scripting, you must use the formatting switches.

Parameter Name Description Example
/FO <FORMAT> Format Output (Essential for Scripts) The output format. TABLE (default), LIST, or CSV. CSV is best for parsing. /FO CSV
/V Verbose Displays much more detailed information for each task, including the author, the command it runs, and the last run time. /V
/NH No Header Suppresses the header line in the output. This can simplify FOR /F loops. /NH

How to Capture and Parse the Task List in a Script

To use the list of tasks in a script, you should format the output as CSV and then process it with a FOR /F loop. This allows you to work with each task's properties individually.

This script lists the name and status of every scheduled task.

@ECHO OFF
SETLOCAL
ECHO --- Capturing Scheduled Task Information ---
ECHO.

REM 'skip=1' ignores the CSV header line.
REM 'tokens=1,3 delims=,' splits the CSV, grabbing the first and third columns.
FOR /F "skip=1 tokens=1,3 delims=," %%A IN ('schtasks /query /FO CSV') DO (
    ECHO Task Name: %%~A, Status: %%~B
)

ENDLOCAL

How the schtasks /query Command Works

The schtasks /query command directly communicates with the Task Scheduler service (Schedule). This service reads the task definition files (XML files) located in C:\Windows\System32\Tasks and its subfolders. The command formats this information and displays it.

Common Pitfalls and How to Solve Them

Problem: The Default Output is Hard to Parse

The default TABLE format is difficult to parse reliably because the columns are separated by a variable number of spaces, and task names can contain spaces.

Solution: Always use the /FO CSV switch when you intend for your script to process the output. The comma is a reliable delimiter that makes parsing with FOR /F simple and robust.

Problem: The List is Too Long (Filtering)

On a typical Windows system, there can be hundreds of built-in scheduled tasks.

Solution: Pipe the output of schtasks /query to findstr to filter for a specific task or group of tasks.

REM Find all tasks related to Google
schtasks /query /FO LIST | findstr /I "Google"

Problem: Not All Tasks are Visible (Administrator Rights)

While a standard user can query tasks, they may not have permission to see tasks created by the SYSTEM account or other users.

Solution: For a complete and accurate inventory of all tasks on a system, you must run the script as an Administrator.

Practical Example: A Scheduled Task Inventory Report

This script uses the robust CSV format to create a comprehensive report of all scheduled tasks and their status, and saves it to the desktop. This is a perfect tool for system auditing.

@ECHO OFF
SETLOCAL
SET "ReportFile=%USERPROFILE%\Desktop\Scheduled_Task_Inventory.csv"

ECHO --- Scheduled Task Inventory Script ---
ECHO Creating report at: "%ReportFile%"

REM Use schtasks with the /V (verbose) and /FO CSV switches.
REM The output is redirected directly into our report file.
schtasks /query /V /FO CSV > "%ReportFile%"

IF %ERRORLEVEL% EQU 0 (
    ECHO.
    ECHO [SUCCESS] Report created successfully.
    START "" "%ReportFile%"
) ELSE (
    ECHO.
    ECHO [FAILURE] An error occurred. Do you have Administrator rights?
)

ENDLOCAL

This simple but powerful script leverages schtasks's own formatting to create a ready-to-use CSV file that can be opened in Excel for sorting and analysis.

Conclusion

The schtasks /query command is the definitive tool for listing scheduled tasks from the command line.

Key takeaways for using it in scripts:

  • For scripting, always use the /FO CSV switch to produce clean, parsable output.
  • Add the /V switch for a more detailed, verbose report.
  • Run your script as an Administrator to get a complete list of all tasks on the system.
  • Use a FOR /F loop to process the CSV output and use the data in your script's logic.
Navigation