7

I want to read the name and the serial number 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:

Invalid Xml-Content. //(Translated)

wmic path win32_physicalmedia get serialnumber

or

wmic DISKDRIVE GET SerialNumber

I tried the following as well:

wmic DISKDRIVE GET SerialNumber /FORMAT:list
wmic DISKDRIVE GET SerialNumber /FORMAT:xml.xsl
wmic DISKDRIVE GET SerialNumber > c:\test.txt

Any ideas on what I'm doing wrong?


Solution:

Thanks JPBlanc, via the /? command I've found out that SerialNumber doesn't even exist. I now use

WMIC /output:"c:\hdds.txt" DISKDRIVE GET PNPDeviceID,Name /Format:CSV

which gives the correct result.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
user1210404
  • 73
  • 1
  • 1
  • 4

3 Answers3

5

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:

  1. Get the ID of each drive: wmic diskdrive get deviceid /format:list

  2. Parse the output and get the first ID. In my case this was \\.\PHYSICALDRIVE0

  3. Escape the backslashes so that the ID is \\\\.\\PHYSICALDRIVE0

  4. Get the serial number of the drive using its escaped ID:

    wmic diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber /format:list

  5. Repeat 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:

wmic path win32_physicalmedia where tag='\\\\.\\PHYSICALDRIVE0' get serialnumber /format:list
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
4

You are just making a mistake usin WMIC command line, WMIC DISKDRIVE GET SerialNumber /Format /? gives you keywords:

CSV
HFORM
HTABLE
LIST
MOF
RAWXML
TABLE
VALUE
XML
htable-sortby
htable-sortby.xsl
texttablewsys
texttablewsys.xsl
wmiclimofformat
wmiclimofformat.xsl
wmiclitableformat
wmiclitableformat.xsl
wmiclitableformatnosys
wmiclitableformatnosys.xsl
wmiclivalueformat
wmiclivalueformat.xsl

you can try :

WMIC /output:"c:\temp\serial1.xml" DISKDRIVE GET SerialNumber /Format:RAWXML

You can replace RAWXML by one of the others formats.

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • soo `wmic diskdrive get serialnumber` produces the output that i need, but i have 6 different drives and it doesnt tell me which serial number belongs to which drive ?? – oldboy May 25 '19 at 02:27
  • Perhaps you can have a look to the model `WMIC DISKDRIVE GET Name,SerialNumber,model` – JPBlanc May 27 '19 at 08:44
  • i figured out how to get the info i needed with HWinfo, but if i need to in the future – oldboy May 27 '19 at 08:47
3

this issue occurs because the XML parser treats the control characters that are included in the serial number of some drives as invalid.

jue
  • 31
  • 2