Getting a list of logical and physical drives from the command line

It’s often useful to know what logical and physical drives are available to Windows, and sometimes this needs to be done from the command line.

Logical drives

Here’s a handy command to return a list of logical drives in Windows.

wmic logicaldisk get caption,description,drivetype,providername,volumename

The Win32_LogicalDisk WMI class represents a data source that resolves to an actual local storage device on a computer system running Windows. While Caption, Description, DriveType, ProviderName, and VolumeName are useful in most cases, more properties are available, and a complete list is available at http://msdn.microsoft.com/en-us/library/windows/desktop/aa394173(v=vs.85).aspx. The output will be formatted as a table, the properties will be the column headings, and they will be placed into alphabetical order.

Caption is the drive letter of the logical disk. The Name property also returns the drive letter.

Description is the type of disk. For example: Local Fixed Disk, CD-ROM Disc, or Removable Disk.

DriveType is returned as an integer that corresponds to the type of disk drive the logical disk represents (and this matches the Description, making DriveType sort of superfluous).

0 = Unknown
1 = No Root Directory
2 = Removable Disk
3 = Local Disk
4 = Network Drive
5 = Compact Disc
6 = RAM Disk

ProviderName is the network path to the logical device.

VolumeName is the volume name of the logical disk.

Physical drives

And here is a command to return a list of physical drives.

wmic diskdrive list brief /format:list

The Win32_DiskDrive WMI class represents a physical disk drive as seen by a computer running Windows. Like the Win32_LogicalDisk WMI class, it has lots of properties, as listed at http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132(v=vs.85).aspx.

For simplicity, though, and ease of reading in command window, wmic diskdrive list brief /format:list does the trick, particularly in combination with wmic logicaldisk.

6 thoughts on “Getting a list of logical and physical drives from the command line

  1. J2u

    Hello,

    How can i extract the specific fields using wmic diskdrive or wmic logicaldisk.

    For example i want to output the size and number or partitions to a text file as follows:

    Partitions:4
    Size:3TB

  2. Michael

    I am trying to create a batch file that automatically select a USB drive if it has a caption ASMedia in its name using WMIC command. I am having problems getting the script to identify the drive so it can be place against a variable so I can then run a diskpart script to prepare it for Windows To Go. I can use Powershell but I dont want to write a script as this is blocked.

    Is there an easy statement that can use WMIC to capture the diskdrive and place the details into a variable I can use within Diskpart to prepare partitions.

    Sorry for it being wordy.

  3. Cvieira

    i think you need this
    for /F “usebackq tokens=1,2,3,4 ” %%i in (`wmic logicaldisk get caption^,description^,VolumeName 2^>NUL`) do (

    if %%l equ MID (
    echo %%i is a USB drive com o nome %%l.
    set android=%%i
    )
    )
    in this case i search for usb drive with name MID in your case you need to change to ASMEDIA
    sorry for the english

  4. Mark Palmos

    Hi
    Trouble is, I have no way of knowing which of the 3 drives in my Storage Space (raid 5) is faulty.
    One drive keeps failing and the Storage Space goes offline…

    Is there a command which will let you know which drive. If I use get-physicaldisk I get a list of drives and all say they are ok, no mention of which drive is causing the failure.

    Thanks!
    Mark.

  5. David Thornton Sr

    I tried this and received a token error
    Any suggestion (looking for U: as the home drive)
    @Echo This is a test of your home drive
    for /F “usebackq tokens=1,2,3,4 ” %%i in (`wmic logicaldisk get drivetype^,deviceID^ 4^`) do (
    if %%l equ U (echo the home drive is present %%l.
    set hdrive=%%i))
    pause

Comments are closed.