Windows script for now hours of your HardDrive
Solution 1:
How can I check Power-On Hours from a command line?
You can do this using DiskSmartView from Nirsoft in a batch file.
GetDiskPowerOnHours.cmd:
@echo off
setlocal enabledelayedexpansion
rem get report using disksmartview from nirsoft
disksmartview /scomma smart.txt
for /f "usebackq tokens=1,2 delims=," %%l in (`type smart.txt`) do (
if "%%l" EQU "Disk Number" (
echo %%l: %%m
)
if "%%l" EQU "Power-On Hours (POH)" (
echo %%l: %%m
)
)
endlocal
Example output:
> GetDiskPowerOnHours
Disk Number: 0
Power-On Hours (POH): 13245
Disk Number: 1
Power-On Hours (POH): 0
Disk Number: 2
Notes:
- Not all drives store the Power-On Hours
- Having said that Power-On Hours is not a useful indicator of hard disk failure (see below)
A Better Solution
Use a SMART monitoring program which will warn you advance of potential problems.
There are many available, including:
-
HDTune
HD Tune Pro is a hard disk / SSD utility with many functions. It can be used to measure the drive's performance, scan for errors, check the health status (S.M.A.R.T.), securely erase all data and much more.
-
HDD Health
HDD Health 4.2 with SSD drives support. HDD Health is a full-featured failure-prediction agent for machines using 2000, XP, Vista, Windows 7 and Windows 8. Sitting in the system tray, it monitors hard disks and alerts you to impending failure. The program uses Self Monitoring and Reporting Technology (S.M.A.R.T.) built into all new hard disks, and can predict failures on your hard drives. A host of alerting features include email, local pop-up messages, net messages, and event logging, while using no system resources.
-
HDD Expert
HDDExpert gives you a crystal-clear vision of your Hard Drive (HDD or SSD) health and performance and translates S.M.A.R.T. attributes into readable indication. It then recommends maintenance (fans upgrade, spare purchase, backups and more) depending on the amount of failures detected on your hard drives.
-
Smartmontools
The smartmontools package contains two utility programs (smartctl and smartd) to control and monitor storage systems using the Self-Monitoring, Analysis and Reporting Technology System (SMART) built into most modern ATA/SATA, SCSI/SAS and NVMe disks. In many cases, these utilities will provide advanced warning of disk degradation and failure. Smartmontools was originally derived from the Linux smartsuite package and actually supports ATA/ATAPI/SATA-3 to -8 disks and SCSI disks and tape devices. It should run on any modern Darwin (Mac OS X), Linux, FreeBSD, NetBSD, OpenBSD, Solaris, OS/2, Cygwin, QNX, eComStation or Windows system.
Predicting hard disk failure
A company called Backblaze has collected data on hard drive failures. It has released that data in company blogs, highlighting which manufacturer's drives failed more often than others.
In Hard Drive SMART Stats it published data indicating exactly which 5 SMART attributes indicate imminent drive failure:
From experience, we have found the following 5 SMART metrics indicate impending disk drive failure:
- SMART 5 – Reallocated_Sector_Count.
- SMART 187 – Reported_Uncorrectable_Errors.
- SMART 188 – Command_Timeout.
- SMART 197 – Current_Pending_Sector_Count.
- SMART 198 – Offline_Uncorrectable.
We chose these 5 stats based on our experience and input from others in the industry because they are consistent across manufacturers and they are good predictors of failure.
The article goes on to suggest:
SMART 5: Reallocated_Sector_Count
1-4 keep an eye on it, more than 4 replace
SMART 187: Reported_Uncorrect
1 or more replace
SMART 188: Command_Timeout
1-13 keep an eye on it, more than 13 replace
SMART 197: Current_Pending_Sector_Count
1 or more replace
SMART 198: Offline_Uncorrectable
1 or more replace
Also from BackBlaze, and worth reading is a newer blog What SMART Stats Tell Us About Hard Drives.
DiskSmartView
DiskSmartView is a small utility that retrieves the S.M.A.R.T information (S.M.A.R.T = Self-Monitoring, Analysis, and Reporting Technology) from IDE/SATA disks. This information includes the disk model/firmware/serial number, cylinders/heads, power-on hours (POH), internal temperature, disk errors rate, and more. You can use the S.M.A.R.T information retrieved by DiskSmartView to find out whether there is any significant problem in your disk drive.
Command-Line Options
/stext <Filename>
Save the S.M.A.R.T information into a regular text file./stab <Filename>
Save the S.M.A.R.T information into a tab-delimited text file./scomma <Filename>
Save the S.M.A.R.T information into a comma-delimited text file (csv)./stabular <Filename>
Save the S.M.A.R.T information into a tabular text file./shtml <Filename>
Save the S.M.A.R.T information into HTML file (Horizontal)./sverhtml <Filename>
Save the S.M.A.R.T information into HTML file (Vertical)./sxml <Filename>
Save the S.M.A.R.T information into XML file.
Source DiskSmartView
Disclaimer
I am not affiliated with Nirsoft in any way, I am just an end user of their software.
Further Reading
- An A-Z Index of the Windows CMD command line
- A categorized list of Windows CMD commands
- for /f - Loop command against the results of another command.
- if - Conditionally perform a command.