Search code examples
wmiserial-numberwmic

wmic diskdrive get serialnumber -> invalid xml output


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.


Solution

  • 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.