I am looking for a way to list drives and the partitions on them. Specifically I am looking to prompt a user for a drive to format and I want to show them the exists partitions so they can confirm their choice.

I have found the wmic commands to list disk drives, logical disks, partitions, and volumes but I can not find a way associate the volumes to physical drives.

I also found a powershell script that does what I want. The script uses gwmi and I don't know how to convert the commands into wmic. http://jrich523.wordpress.com/2011/12/12/using-wmi-to-link-a-disk-volume-to-a-physical-disk-with-powershell/

Is there a way to get a list of volumes on a physical disk using wmic?


The wmic command is a bit different then either the VB or Powershell syntax.

The relevant syntax for wmic is:

wmic <command> where <conditional> Assoc /assocclass:<class>

Specifically to solve the task above:

wmic DiskDrive where "DeviceID='\\\\.\\PHYSICALDRIVE<disk_index>'" Assoc /assocclass:Win32_DiskDriveToDiskPartition

Will return the partitions on the drive with the given index.

wmic partition where (DeviceID="<partition_id>") assoc /assocclass:Win32_LogicalDiskToPartition

Will return the volumes on the partition with the given id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.