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.