问题
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.
回答1:
Found this on the Google: https://blogs.msdn.microsoft.com/san/2011/08/11/have-you-ever-wanted-to-know-if-your-disk-is-going-to-fail-before-it-does/
Get-WmiObject `
-namespace root\wmi `
–class MSStorageDriver_FailurePredictStatus `
-ErrorAction Silentlycontinue `
| Select InstanceName, PredictFailure, Reason `
| Format-Table –Autosize
回答2:
I think this is what you need:
Get-Disk | foreach { $_ | Get-StorageReliabilityCounter | Format-List }
This should give you the ReadErrorsCorrected
and WriteErrorsCorrected
stats for all of the connected disks.
I can't find the relevant piece of Microsoft documentation to ensure I'm 100% correct here, but based on this documentation, I am assuming that the Reallocated Sectors Count is the total of corrected read/write sectors: https://kb.acronis.com/content/9105
回答3:
Get-WmiObject -query "Select * from Win32_diskdrive" | select ReallocatedSectorCount
回答4:
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.
来源:https://stackoverflow.com/questions/58453447/smart-hard-drive-info-powershell