5 thoughts on “ Getting a list of logical and physical drives from the command line ” J2u 30 January 2014 at 4:47 pm. 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. You can get it by using a command at command prompt: C: > vol c: if C: is the drive you want to retrieve the Volume Serial Number for. This command gets an instance of the Win32_DiskDrive WMI class and outputs the model of each disk drive in the computer and its corresponding serial number from that instance.
I want to read the name and the serialnumber of my Hard-Drives.
I stumbled upon wmic but i'm having troubles. I guess these two commands should do the trick, but I only get the message:
or
I tried the following aswell:
Any ideas on what I'am doing wrong?

Solution:
Thanks JPBlanc,via the /? command i've found out that SerialNumber doesn't even exist. I now use
which gives the correct result.
Paul Hiemstra3 Answers
You are just making a mistake usin WMIC command line, WMIC DISKDRIVE GET SerialNumber /Format /? gives you keywords:
Serial Number Lookup
you can try :
You can replace RAWXML by one of the others formats.
this issue occurs because the XML parser treats the control characters that are included in the serial number of some drives as invalid.
I was getting this error on Windows 7 x86 Pro (where querying the serial number should be possible) when an external drive was connected.
This is how I fixed it:
Get the ID of each drive:
wmic diskdrive get deviceid /format:listParse the output and get the first ID. In my case this was
.PHYSICALDRIVE0Escape the backslashes so that the ID is
.PHYSICALDRIVE0Get the serial number of the drive using its escaped ID:
wmic diskdrive where deviceid='.PHYSICALDRIVE0' getserialnumber /format:listRepeat steps 2 - 4 until you have the serial numbers of all drives
Edit: The above doesn't work on my copy of Windows XP x86 Pro.
This does:
Matthias BraunMatthias Braun
Not the answer you're looking for? Browse other questions tagged wmiserial-numberwmic or ask your own question.
How to get Hard Disk number from drive letter using VBScript?
Thank you in advance.
Leonid F.Leonid F.3 Answers
Remou is right about WMI, just have to make it a little bit more messy. Wouldn't be at all surprised if there's an easier/better way of doing this, but this script should at least give you a good starting point for doing what you need.
This will enumerate all drive letters and give you the results as for example: C: - Disk #2, Partion #0
Win32_diskdrive Serial Number C++
Hans OlssonThis is not the exact answer but in case some need it in C# use this function that I just created
Ricardo PoloRicardo PoloWin32_diskdrive Serial Number Windows Xp
