I am looking for a way through possibly powershell to obtain the SMART data for a hard drive on any given device.
I have tried the WMI commands both through CMD and powershell that I have seen but have not been able to get the appropriate data I am looking for.
Get-WmiObject -list
I hoped to find something for SMART or REallocated space in this list but nothing related is found. Anyone know of a way to pull the smart data from the drive without using a 3rd party app. I want to automate a process of identifying failing drives but require specific info to be relayed not just yes or no its possible to fail.
In your question, you've requested both generic S.M.A.R.T. information and also information specific to reallocated sectors. I'll address S.M.A.R.T. interaction via PowerShell first, then give example code to return the property relating to reallocated sectors (also known as the ReadErrorsCorrected
property). This should allow you to target the specified attribute and other S.M.A.R.T. attributes where needed.
--- Preface: ---
Unfortunately, there doesn't appear to be a way of obtaining all S.M.A.R.T. information available from various storage devices via PowerShell only, as it is a rather generic implentation of the functionality, and S.M.A.R.T. is varied in its implementation across storage device vendors.
Having said that, the method described below should satisfy the key requirements of typical S.M.A.R.T. checks performed by users, including predicted lifespan, reallocated and uncorrectable sectors, etc., though using rather generic PowerShell terminology (e.g. lifespan = "Wear").
--- Information: ---
With a combination of two PowerShell cmdlets, we can easily view some of the the S.M.A.R.T. data offered by storage devices:
Get-StorageReliabilityCounter
"The Get-StorageReliabilityCounter cmdlet gets the storage reliability counters for the specified disk or physical disk. These counters include information about such things as the device temperature, errors, wear, and length of time the device has been in use."
This is the cmdlet that will actually return the S.M.A.R.T. data we seek. However, unlike many other cmdlets you may be familiar with, this cmdlet needs to be pointed to the target disk(s) by way of a PowerShell object(s). (If you're new to PowerShell, this is not as complex as it may sound, so fear not.)
Get-Disk
"The Get-Disk cmdlet gets one or more Disk objects visible to the operating system, or optionally a filtered list."
This is the cmdlet we will use to provide the required PowerShell object(s), so that Get-StorageReliabilityCounter knows which disk(s) to query.
--- Code: ---
As with anything, there are multiple ways to actually execute the code, so I'm just going to provide code to obtain the desired information in the simplest way possible, in my opinion.
For simple S.M.A.R.T. information on all local disks (run as Administrator):
Get-Disk | Get-StorageReliabilityCounter
Sample output:
PS C:\WINDOWS\system32> Get-Disk | Get-StorageReliabilityCounter
DeviceId Temperature ReadErrorsUncorrected Wear PowerOnHours
-------- ----------- --------------------- ---- ------------
1 0 0 5505
2 0 0 572
0 0 2799
For extended S.M.A.R.T. information on all local disks (run as Administrator):
Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
Truncated sample output:
PS C:\WINDOWS\system32> Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
DeviceId : 1
FlushLatencyMax : 46
LoadUnloadCycleCount :
LoadUnloadCycleCountMax :
ManufactureDate :
PowerOnHours : 5505
ReadErrorsCorrected : 0
ReadErrorsTotal : 0
ReadErrorsUncorrected : 0
ReadLatencyMax : 231
StartStopCycleCount :
StartStopCycleCountMax :
Temperature : 27
TemperatureMax : 0
Wear : 0
WriteErrorsCorrected :
WriteErrorsTotal :
WriteErrorsUncorrected :
WriteLatencyMax : 69
PSComputerName :
As you can see, listed are some of those desirable indicators that may or may not allow you to circumvent disaster.
For obtaining the values contained in the ReadErrorsCorrected
property (also known as reallocated sectors) (run as Administrator):
Get-Disk | Get-StorageReliabilityCounter | Select-Object -ExpandProperty "ReadErrorsCorrected"
Sample output:
PS C:\WINDOWS\system32> Get-Disk | Get-StorageReliabilityCounter | Select-Object -ExpandProperty "ReadErrorsCorrected"
0
From this point, some script to detect any reallocated sectors could check to see if this value is anything other than 0
and report accordingly.
--- tl;dr: ---
Run
Get-Disk | Get-StorageReliabilityCounter
or
Get-Disk | Get-StorageReliabilityCounter | Select-Object -Property "*"
as Administrator to get most important S.M.A.R.T. information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With