Search code examples
batch-filecmdwmic

Get the drive letter from Partition Index


I want to get the drive letter from Partition Index.

wmic path Win32_LogicalDiskToPartition WHERE Antecedent='Win32_DiskPartition.DeviceID=\'Disk #1 AND Partition #0\'' Get Dependent

Result: No Instance(s) Available


Solution

  • The following should output your information, you'd obviously need to parse it further to select the drive letter from that.

    WMIC Partition Where (DeviceID="Disk #1, Partition #0") Assoc /ResultRole:Dependent 2>NUL
    

    Alternatively:

    WMIC Partition Where (DeviceID="Disk #1, Partition #0") Assoc /AssocClass:Win32_LogicalDiskToPartition 2>NUL