Skip to main content

How to List All Physical Disks in a Batch Script

In system administration and diagnostics, you often need to look beyond logical volumes (like C: and D:) and get information about the physical disks installed in the machine. A physical disk is the actual hardware device (the SSD or HDD) that contains the partitions and volumes. Listing these disks is essential for tasks like checking the health of a drive, getting its serial number, or preparing for a partitioning operation.

This guide will teach you how to list all physical disks using the two primary built-in utilities for this task: the powerful and script-friendly WMIC command, and the interactive diskpart shell. For scripting, WMIC is the highly recommended method.

What is a Physical Disk? (vs. a Volume)

It's critical to understand the difference between these two concepts:

  • Physical Disk: The actual hardware device installed in your computer. It is identified by an index number (Disk 0, Disk 1, etc.).
  • Volume (or Partition): A formatted section of a physical disk. A single physical disk can be divided into multiple volumes (e.g., a C: drive, a D: drive, and a hidden recovery partition all on Disk 0).

The tools in this guide list the physical disks.

The WMIC (Windows Management Instrumentation Command-line) utility is the best tool for getting hardware information in a script-friendly format. The DISKDRIVE alias provides direct access to physical disk information.

Command: WMIC DISKDRIVE GET Index,Model,Size,Status

  • DISKDRIVE: The WMI class for physical disk drives.
  • GET ...: Specifies the properties you want to display.

This command produces a clean, well-structured table that is perfect for scripts.

Index  Model                   Size          Status
0 Samsung SSD 970 EVO 500GB 500105249280 OK
1 WDC WD40EZAZ-00SF3B0 4000783933440 OK

Method 2 (For Display): Using diskpart

The diskpart.exe utility is an interactive shell for disk management. Its list disk command provides a quick, human-readable summary of the installed physical disks.

For example, to use this in a non-interactive script, you must feed it a command script file.

@ECHO OFF
REM This script requires Administrator privileges.
SET "DISKPART_SCRIPT=%TEMP%\list_disks.txt"

ECHO list disk > "%DISKPART_SCRIPT%"

ECHO --- Listing physical disks using diskpart ---
diskpart /s "%DISKPART_SCRIPT%"

DEL "%DISKPART_SCRIPT%"

The output is formatted for people, not scripts, but clearly shows the disk index and size.

  Disk ###  Status      Size     Free     Dyn  Gpt
-------- ---------- ------- ------- --- ---
Disk 0 Online 465 GB 0 B *
Disk 1 Online 3726 GB 0 B *

Parsing the WMIC Output to Process Each Disk

The real power of the WMIC method is the ability to use its output in a FOR loop to perform an action on each physical disk.

This script iterates through each physical disk and prints its index number.

@ECHO OFF
ECHO --- Iterating through all physical disks ---
ECHO.

REM The 'skip=1' ignores the header line of the WMIC output.
FOR /F "skip=1 tokens=1" %%D IN ('WMIC DISKDRIVE GET Index') DO (
ECHO Found Physical Disk Index: %%D
)

Output:

--- Iterating through all physical disks ---

Found Physical Disk Index: 0
Found Physical Disk Index: 1

Key WMIC DISKDRIVE Properties Explained

You can GET many useful properties from the DISKDRIVE class:

  • Index: The disk number used by the system (e.g., 0).
  • Model: The manufacturer's model name (e.g., "Samsung SSD 970 EVO 500GB").
  • SerialNumber: The unique serial number of the hardware.
  • Size: The total size of the disk in bytes.
  • Status: The health status of the disk (e.g., OK, Pred Fail).
  • Partitions: The number of partitions on the disk.
  • MediaType: Indicates the type of drive (e.g., "Fixed hard disk media" for HDD, "SSD" for Solid State Drive).

Common Pitfalls and How to Solve Them

  • Administrator Rights: Querying low-level hardware information is a privileged operation. For a complete and accurate list, your script must be run as an Administrator.
  • WMIC Output Quirks: WMIC output can sometimes include invisible trailing carriage return characters. Solution: Clean any variable captured from WMIC by re-assigning it in a simple FOR loop: FOR %%N IN ("%Var%") DO SET "Var=%%~N".
  • External Drives: Both diskpart and WMIC will list all connected physical disks, including external USB hard drives and flash drives. You can use the MediaType or InterfaceType (USB) properties in WMIC to filter these if needed.

Practical Example: A Detailed Disk Inventory Report

This script uses the robust WMIC method to generate a detailed report of every physical disk installed in the system, saving it to a file.

@ECHO OFF
SETLOCAL
SET "ReportFile=%USERPROFILE%\Desktop\Disk_Inventory.txt"

ECHO --- Generating Disk Inventory Report ---
ECHO Saving report to: "%ReportFile%"
ECHO.

(
ECHO System Disk Inventory
ECHO Generated on: %DATE% %TIME% for %COMPUTERNAME%
ECHO ==================================================
) > "%ReportFile%"

REM The 'skip=1' ignores the header.
FOR /F "skip=1 tokens=1,2,*" %%A IN ('WMIC DISKDRIVE GET Index^,Model^,SerialNumber^,Size^,Status') DO (
(
ECHO.
ECHO --- Disk %%A ---
ECHO Model: %%B
ECHO Serial Number: %%C
ECHO Size (Bytes): %%D
ECHO Status: %%E
) >> "%ReportFile%"
)

ECHO [SUCCESS] Report created.
ENDLOCAL

Conclusion

While both diskpart and WMIC can list the physical disks in a system, they are suited for different goals.

  • diskpart is best for a quick, human-readable display in an interactive session.
  • WMIC DISKDRIVE is the overwhelmingly superior and recommended method for scripting. It provides clean, predictable, and detailed output that can be easily captured in a FOR loop for automation.

By using WMIC, you can write powerful scripts to audit, report on, and manage the physical hardware of your Windows systems.