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'
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.
At the same time, 3rd party software can clearly show both physical and virtual disks (storage spaces itself) and can show SMART for them:
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.
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: