Skip to main content

How to Get the S.M.A.R.T. Status of a Hard Drive in Batch Script

S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology) is a monitoring system built into modern hard disk drives (HDDs) and solid-state drives (SSDs). It tracks various health indicators, such as read error rates, temperature, and reallocated sector counts. The most critical piece of information it provides is a general health status, which can predict imminent hardware failure.

This guide will teach you how to use the built-in WMIC (Windows Management Instrumentation Command-line) utility to query the S.M.A.R.T. status of your drives. This allows you to create a simple but powerful script to check the health of your storage devices, an essential part of any proactive system maintenance routine.

What is S.M.A.R.T. Status?

The S.M.A.R.T. system continuously monitors the drive. Based on its internal diagnostics, it reports a general status. For scripting purposes, this is usually simplified to a single word. The Status property from WMI typically returns one of the following:

  • OK: The drive is healthy.
  • Pred Fail: Predictive Failure. This is a critical warning. The drive has reported that it is likely to fail soon. This is a clear signal to back up your data immediately and replace the drive.
  • Error: The drive is reporting other, non-specific errors.

The Core Command: WMIC DISKDRIVE GET

The WMIC utility is the standard tool for querying hardware. The DISKDRIVE alias lets us access the Win32_DiskDrive WMI class, which contains the S.M.A.R.T. status.

Syntax: WMIC DISKDRIVE GET Model, Status

  • WMIC: The command-line utility.
  • DISKDRIVE: The alias for physical storage devices.
  • GET Model, Status: The properties we want to retrieve.

Basic Example: A Simple Health Check

You can run this command directly in a command prompt to see the health of all installed drives.

@ECHO OFF
ECHO --- Querying S.M.A.R.T. Drive Health Status ---
ECHO.
WMIC DISKDRIVE GET Model, Status

The output is a simple table showing each drive and its reported status.

--- Querying S.M.A.R.T. Drive Health Status ---

Model Status
Samsung SSD 860 EVO 500GB OK
WDC WD10EZEX-00WN4A0 OK

How to Capture and Interpret the Status in a Script

To create a script that can act on this information, you need to capture the status for each drive and check its value. The best way to do this is to have WMIC format the output as CSV and parse it with a FOR /F loop.

@ECHO OFF
SETLOCAL
ECHO --- Checking S.M.A.R.T. Status of All Drives ---
ECHO.

REM 'skip=1' ignores the header. 'tokens=2-3' grabs the Model and Status columns.
FOR /F "skip=1 tokens=2,3 delims=," %%A IN (
'WMIC DISKDRIVE GET Model,Status /FORMAT:CSV'
) DO (
SET "DriveModel=%%~A"
SET "DriveStatus=%%~B"

REM --- The Conditional Check ---
IF /I "!DriveStatus!"=="OK" (
ECHO [OK] - !DriveModel!
) ELSE (
ECHO [!!CRITICAL WARNING!!] - !DriveModel! - Status: !DriveStatus!
)
)

ENDLOCAL
note

DelayedExpansion (!) is used here to correctly handle the variables inside the loop.

How the Command Works

The WMIC DISKDRIVE GET Status command sends a query through the WMI service to the storage device drivers. These drivers, in turn, issue a "RETURN STATUS" command to the drive's firmware via the ATA or NVMe protocol. The drive's controller then responds with its current, internally-calculated S.M.A.R.T. health status, which WMI formats and returns.

Common Pitfalls and How to Solve Them

Problem: Interpreting the Status

The most important part of this check is knowing what to look for. The only truly "good" status is OK.

Solution: Your script's logic should be simple: if the status is anything other than OK, it should be treated as a failure or a critical warning that requires immediate human attention.

Problem: The System Has Multiple Drives

The WMIC command will list all physical drives. The FOR /F loop in the example script is designed to handle this correctly, iterating through each drive and reporting on it individually. This is the desired behavior.

Problem: USB External Drives

S.M.A.R.T. data is not always reliably passed through a USB connection. Many USB-to-SATA controller chips in external drive enclosures do not support the necessary commands to retrieve the S.M.A.R.T. status.

Solution: Don't be surprised if your USB external hard drive does not report a status or appears to be missing from the WMIC DISKDRIVE list. This is a hardware limitation. The check is most reliable for internal SATA and NVMe drives.

Practical Example: A "Disk Health Check" Report

This script is designed to be run as part of a scheduled maintenance task. It checks all drives and creates a log file. If it detects a failure, it will report it prominently.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "LogFile=C:\Logs\Disk_Health_Report.log"

ECHO %DATE% %TIME% - Starting Disk Health Check... > "%LogFile%"
ECHO ==================================================== >> "%LogFile%"

SET "FailuresFound=0"

FOR /F "skip=1 tokens=2,3 delims=," %%A IN ('WMIC DISKDRIVE GET Model,Status /FORMAT:CSV') DO (
SET "DriveModel=%%~A"
SET "DriveStatus=%%~B"

ECHO Drive: "!DriveModel!", Status: !DriveStatus! >> "%LogFile%"

IF /I "!DriveStatus!" NEQ "OK" (
SET "FailuresFound=1"
)
)

ECHO. >> "%LogFile%"
IF %FailuresFound% EQU 1 (
ECHO [CRITICAL] - One or more drives reported a non-OK status! >> "%LogFile%"
ECHO Please check the drive health immediately. >> "%LogFile%"
) ELSE (
ECHO [SUCCESS] - All drives reported OK status. >> "%LogFile%"
)

ENDLOCAL

Conclusion

The WMIC DISKDRIVE GET Status command is the definitive, built-in method for checking the S.M.A.R.T. health of your storage devices from a batch script.

Key takeaways:

  • A status of OK means the drive is healthy. Any other status, especially Pred Fail, is a critical warning.
  • For scripting, always use /FORMAT:CSV to get clean, parsable output from WMIC.
  • Use a FOR /F loop to iterate through all physical drives and check their status.
  • Be aware that USB external drives may not report S.M.A.R.T. status.

By incorporating this simple check into your regular maintenance scripts, you can get an early warning of potential drive failure and prevent catastrophic data loss.