See available drives from Windows CLI?

102

44

Is there a way to list the available drives from cmd.exe ? (Other than manually typying

c:
d:
...

and seeing which ones return errors)

Cristi Diaconescu

Posted 2010-05-11T12:01:44.770

Reputation: 2 810

Answers

123

> wmic logicaldisk get caption

Caption
C:
D:
E:

if probably the easiest one. Doesn't need administrative privileges, doesn't return more or less than what's needed, etc.

If you want to use it in a script, then wrap it in for /f with the skip=1 option:

for /f "skip=1 delims=" %%x in ('wmic logicaldisk get caption') do @echo.%%x

Joey

Posted 2010-05-11T12:01:44.770

Reputation: 36 381

1only for users with administrator rights – Carlos Campderrós – 2015-04-16T16:16:44.593

1@CarlosCampderrós: works fine for me from a limited user account. – Joey – 2015-04-16T16:51:17.123

1

Quoting from https://support.microsoft.com/en-us/kb/290216 "Wmic.exe can only be used by the local system administrators regardless of WMI namespace permissions on the local machine", and it failed on my machine (a VM with winXP)

– Carlos Campderrós – 2015-04-17T08:42:50.813

4It worked just fine under a non-admin account on a Windows 8.1 here. Note that the KB article applies only to legacy operating systems. – Joey – 2015-04-17T10:33:50.683

1@Joey, Why caption instead of wmic logicaldisk get name? – Pacerier – 2015-04-23T17:33:02.583

Got: Failed to register mof file(s). Only the administrator group members can use WMIC.EXE. Reason:Win32 Error: Access is denied. – Ajedi32 – 2015-07-06T17:18:34.973

This looks good too, including the volume name: wmic logicaldisk get caption,volumename. – Kody Brown – 2015-07-29T15:35:02.387

doesn't work on MSDos – Tomáš Zato - Reinstate Monica – 2016-05-23T08:28:37.450

@TomášZato: Of course not. The question was about the Windows command line (it even says so in both the title and the question), not MS DOS. – Joey – 2016-05-23T08:56:51.550

Use "NET USE" for listing the network mapped drives. – Francisco Luz – 2016-11-30T18:04:59.167

'wmic' is not recognized as an internal or external command, – Karl Morrison – 2019-10-01T10:13:30.360

68

If you're in Command Prompt:

diskpart

then

list volume

sample output:

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     E                       DVD-ROM         0 B  No Media
  Volume 1         System Rese  NTFS   Partition    100 MB  Healthy    System
  Volume 2     C   System       NTFS   Partition     99 GB  Healthy    Boot
  Volume 3     F   Data (local  NTFS   Partition    365 GB  Healthy

and finally

exit

to return to the command line.

Mike Fitzpatrick

Posted 2010-05-11T12:01:44.770

Reputation: 15 062

in contrast to the net use command, this will only list local physical drives. (i think.) see diskpart at technet and diskpart at support.microsoft.com

– quack quixote – 2010-05-11T12:33:48.300

3diskpart needs administrative privileges. If you just want a list of drive letters that's a bit much to ask for ... – Joey – 2010-05-11T13:30:07.750

'diskpart' is not recognized as an internal or external command, – Karl Morrison – 2019-10-01T10:13:53.783

19

For the sake of completeness, there is yet another way:

fsutil fsinfo drives

which returns:

Drives: C:\ D:\ E:\ F:\

(Not a very scripting-friendly output, but it may be useful for human eye)

Some reference. That should work since win2k but only with Administrator account.

(Thanks @Carlos Campderrós for enhancing the answer)

saulius2

Posted 2010-05-11T12:01:44.770

Reputation: 371

4It should be noted that this only work if you are using an Administrator account – Carlos Campderrós – 2015-04-16T16:11:34.580

@CarlosCampderrós I don't think that's correct. I can run fsutil with a limited user, and the result is much faster than spinning up the wmic system. On my box with only SSDs running windows 10 v 1803, wmic takes 100-200ms, and fsutil takes ~20ms. – mrm – 2018-09-20T18:24:47.237

@mrm, some windows version (or release, or build of w10) probably losened this restriction. I tested this on wxp and w7pro, and it failed without an admin account (AFAIR). – saulius2 – 2018-09-20T18:48:11.877

I second the observation by @saulius2 – Fr0zenFyr – 2019-07-18T04:46:54.827

8

If you're using powershell then you can type in

get-psdrive -psprovider filesystem

Edited in response to comments to only show filesystems

Matthew Steeples

Posted 2010-05-11T12:01:44.770

Reputation: 2 130

This is the only answer that worked for me. All other solutions seem to require administrator access. (At least on my horribly outdated Windows XP system.) – Ajedi32 – 2015-07-06T17:22:40.667

That will also return other non-filesystem drives that are mounted, such as Cert:, Alias: and Function:. Furthermore, it will return other file-system directories mounted as a PSDrive (such as Home: for %UserProfile% for me). – Joey – 2010-05-11T13:31:07.093

5

wmic logicaldisk get volumename,name

You can get (query) multiple properties this way.  This will give you the partition/drive letter and the label you gave the drive/partition when you formatted the drive:

Name  VolumeName
C:    OS
D:    Data
E:    Programs

For help and to list all the permission options:

wmic logicaldisk /?

then

wmic logicaldisk get /?

Marcus O'Brien

Posted 2010-05-11T12:01:44.770

Reputation: 51

I was trying to get the drive letter of the CD/DVD ROM and the closest thing I could find to get that is wmic logicaldisk get name,filesystem. Normal drives will list as NTFS or FAT32, and the CD/DVD ROM's filesystem will be empty. – akinuri – 2018-05-13T13:51:56.520

Correction: if the drive is empty, filesystem is empty. If not, e.g. I have Windows 10 disc in it at the moment, and it's listed as UDF. – akinuri – 2018-05-13T13:58:55.190

5

Use the doskey built in function to create an alias that runs the wmic command with the necessary atributes

doskey v=wmic logicaldisk get caption

This will create an aliases "v" that whenever typed will run the given command and list all volume letters.

user216496

Posted 2010-05-11T12:01:44.770

Reputation: 51

oh nice, didn't know about doskey (like powershell's Set-Alias) – BananaAcid – 2016-06-15T22:17:45.640

Highly underrated answer, been using CMD for years and never realised aliases were a thing with it. – Hashim – 2019-04-15T18:41:17.447