Share via

MSFT_Disk to MSFT_PhysicalDisk

Halifax Crosby 160 Reputation points
2026-05-16T14:01:16.5266667+00:00

Hello, because MSFT_PhysicalDisk does not have IsSystem like MSFT_Disk, how can I get MSFT_Disk WHERE IsSystem = TRUE and correlate it to MSFT_PhysicalDisk to be sure it's always reliable under all conditions/configurations?

Using MySearcher1 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "SELECT * FROM MSFT_Disk WHERE IsSystem = TRUE", WMIOptions)
    For Each MyDisk As ManagementObject In MySearcher1.Get()
        Using MySearcher2 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "ASSOCIATORS OF {" + how??? + "} WHERE ResultClass=MSFT_PhysicalDisk", WMIOptions)
            For Each pd As ManagementObject In MySearcher2.Get()
               Get pd("Blah").ToString
            Next
        End Using
    Next
End Using

Thanks

Windows development | Windows API - Win32
0 comments No comments

3 answers

Sort by: Most helpful
  1. RLWA32 52,566 Reputation points
    2026-05-18T13:19:54.1733333+00:00

    The MSFT_StorageReliabilityCounter class is an associator of both MSFT_Disk and MSFT_PhysicalDisk. The documentation for its DeviceId property states that it is "An identifier that uniquely names the associated storage device. When associated with an MSFT_PhysicalDisk, it will be the same as its DeviceId member. When associated with an MSFT_Disk, it will be the same as its Number field."

    Consequently, you can directly relate an MSFT_DIsk instance to its related MSFT_PhysicalDisk instance as follows:

            Using MySearcher1 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "SELECT * FROM MSFT_Disk WHERE IsSystem = TRUE")
                For Each MyDisk As ManagementObject In MySearcher1.Get()
                    Dim disknumber As Integer = MyDisk("Number")
                    Console.WriteLine($"MSFT_Disk Number property is {disknumber}")
                    '
                    ' Uncomment below if running as Administrator
                    '
                    'Dim src As ManagementObject = MyDisk.GetRelated("MSFT_StorageReliabilityCounter")(0)
                    'Dim srcId As String = src("DeviceId")
                    'Console.WriteLine($"MSFT_Disk->StorageReliabilityCounter device Id is {srcId}")
                    Using MySearcher2 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", $"SELECT * FROM MSFT_PhysicalDisk WHERE DeviceId = ""{disknumber}""")
                        For Each pd As ManagementObject In MySearcher2.Get()
                            Dim devId As String = pd("DeviceId")
                            Console.WriteLine($"MSFT_PhysicalDisk DeviceId property is {devId}")
                            '
                            ' Uncomment below if running as Administrator
                            '
                            'Dim src2 As ManagementObject = pd.GetRelated("MSFT_StorageReliabilityCounter")(0)
                            'Dim src2Id As String = src2("DeviceId")
                            'Console.WriteLine($"MSFT_PhysicalDisk->StorageReliabilityCounter device Id is {src2Id}")
                        Next
                    End Using
                Next
            End Using
    

    If running with Administrator privileges you can uncomment the indicated statements to see the value from the MSFT_StorageReliabilityCounter associator.

    Was this answer helpful?

    0 comments No comments

  2. Taki Ly (WICLOUD CORPORATION) 1,500 Reputation points Microsoft External Staff Moderator
    2026-05-18T03:21:57.1266667+00:00

    Hello @Halifax Crosby ,

    To correlate MSFT_Disk with MSFT_PhysicalDisk reliably, you can use the built-in .GetRelated() method provided by the ManagementObject class instead of manually constructing a second WQL query. According to the Microsoft documentation, calling .GetRelated("ResultClassName") is equivalent to executing an ASSOCIATORS OF query where the ResultClass is specified.

    The advantage of using this method is that it operates directly on the object. You do not need to manually extract the object's WMI path and concatenate it into a string. This inherently avoids WQL syntax errors (such as Invalid query) that can occur if the device path contains special characters (like \ and ") that are not properly escaped in the query string.

    You can structure your code this like one below:

    Using MySearcher1 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "SELECT * FROM MSFT_Disk WHERE IsSystem = TRUE", WMIOptions)
        For Each MyDisk As ManagementObject In MySearcher1.Get()
            ' Use GetRelated to retrieve the associated MSFT_PhysicalDisk directly
            For Each pd As ManagementObject In MyDisk.GetRelated("MSFT_PhysicalDisk")
                ' You now have the correlated physical disk
                Dim friendlyName As String = pd("FriendlyName").ToString()
                Console.WriteLine("Physical Disk: " & friendlyName)
            Next
        Next
    End Using
    

    Hope this alternative helps you out. If you found my response helpful or informative, I would greatly appreciate it if you could provide feedback by following this guide.

    Thank you.

    Was this answer helpful?


  3. Viorel 126.9K Reputation points
    2026-05-16T17:19:03.6366667+00:00

    Maybe it can be solved in this manner:

    Using MySearcher1 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", "SELECT * FROM MSFT_Disk WHERE IsSystem = TRUE")
        For Each MyDisk As ManagementObject In MySearcher1.Get()
            Using MySearcher2 As New ManagementObjectSearcher("root\Microsoft\Windows\Storage", $"SELECT * FROM MSFT_PhysicalDisk WHERE UniqueId=""{MyDisk.GetPropertyValue("UniqueId")}""")
                For Each MyPhisicalDisk As ManagementObject In MySearcher2.Get()
                    ' . . .
                Next
            End Using
        Next
    End Using
    

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.