0
votes

There are 2 most popular ways: PowerShell (PowerShell.Create()...) and WMI (ManagementObjectSearcher).

1) PowerShell Get-PhysicalDisk can retrieve disks properly, but it doesn't have VendorSpecific property (SMART). There is Get-StorageReliabilityCounter that populates some common SAMRT properties, but not all of them. Specifically it does not show 'Reallocated Sectors Count' and 'Pending Sectors'

enter image description here enter image description here

2) WMI SELECT * FROM Win32_DiskDrive can be queried but this one shows virtual disks. Actual physical disks is not there. For software RAID (Add Mirror in Disk Management) or for Storage Spaces actual physical disks are already filtered out. SELECT * FROM MSStorageDriver_FailurePredictData shows SMRART (VendorSpecific) information that I'm looking for, but there no physical drives as well and no way to associate the 'InstanceName' with actual list of a disk.

enter image description here

At the same time, 3rd party software can clearly show both physical and virtual disks (storage spaces itself) and can show SMART for them:

enter image description here

At the end of the day I want to have it in .Net application and I googled some code how to extract this info (Reallocated Sectors Count) from VendorSpecific field of WMI object, but I just don't see WMI object of actual physical disks.

1
There is .net version of the code you are looking for here. derekwilson.net/blog/2017/08/26/smart . It should get you started. I recommend that you do not go down that path. It is a hot mess. Many of programs that read smart data are using smartclt.exe in the background. I recommend smartclt.exe. It is command line and you can parse the output into your script.Aaron
@Aaron, yep, thanks, I've seen this one. But because it is just a wrapper over WMI, it have the same problem. Does not work neither with software RAID nor with StorageSpaces. Also I figured out that WMI does not show USB drives, and I need this for the other server :(Dmitry Gusarov

1 Answers

0
votes

Apparently the main problem for me was USB drives on a small home server. There is no easy solution for USB devices on Storage Spaces or RAID. All existing software have tons of proprietary code to support SMART over USB for different manufacturers (notably CrystalDiskInfo that can easily show all SMART for all USB drives hidden behind Storage Spaces), so it is far from 100 lines of C# code solution.

But I found that initial problem (2 Records that I need) is actually solved by PowerShell, Microsoft just renamed some metrics making them user friendly.

This is how SMART converted to -> PowerShell Get-StorageReliabilityCounter

Reallocated Sectors Count -> ReadErrorsCorrected

Pending Sectors -> ReadErrorsUncorrected

This became clear when I got both records on one of the drives:

enter image description here