How do I get a list of drive letters and their associated labels on a windows system through a bat file?
|
feedback
|
|
This will get most of it:
If you have any drives mapped via subst you would also need to get those:
For completeness, you would do it like this in Powershell (if you are on windows 7 or have installed it):
You can also do it from the command prompt or a batch file using WMI like this:
| |||||||||||||
feedback
|
Fast, flexible and efficient. Although a little complex. | |||||||
feedback
|
|
inspired by Scott
also shows CD drive letter. no need to be admin. | ||||
|
feedback
|
|
@echo off echo list volume > scriptdiskpart diskpart/s scriptdiskpart del scriptdiskpart pause | |||
feedback
|
|
Somewhat kludgy, but works from a batch file:
| |||
|
feedback
|
|
If anyone is lucky enough to be using Vista (Vista Ultimate SP2 b6002, in my case) and the gwmi and wmic snippets given here don't work exactly, here is what I did to make it work. For gwmi, if you receive no output, try changing the DriveType to 3. If still having problems, remove the -filter option altogether and analyze output.
For wmic, if you receive "Invalid GET Expression", then try putting the get expression in quotes:
| |||
|
feedback
|
|
for %a in (c: d: e: f: g: h: i: j: k: l: m: n: o: p: q: r: s: t: u: v: w: x: y: z:) do @vol %a 2>&1 | find "drive"
| |||
|
feedback
|
| |||||||||
feedback
|