50

From the Windows NT-based (Windows XP and 7 specifically) command prompt, how can I get the serial number of a hard drive as a variable? The one I'm looking at is the serial number of the physical hard disk drive

3

5 Answers 5

63

Try this command

vol C:

this will get the volume serial number given to it by windows.

wmic diskdrive get serialnumber

this gets the manufacturers serial number of the hard drive.

12
  • I don't see that in his question, maybe he needs to re-word the title dude, "How to get hard drive serial number from command line?"
    – Moab
    Nov 2, 2012 at 2:42
  • When using wmic diskdrive get serialnumber I get the message Invalid XML. What does it mean?
    – Maxbester
    May 27, 2013 at 8:00
  • I get invalid query error for wmic diskdrive get serialnumber.
    – atoMerz
    Feb 10, 2014 at 7:49
  • 1
    @Maxbester and @atoMerz: I had both problems. Invalid XML was due to having more than one drive connected and Invalid query occurred because I was on Windows XP. See this answer for both issues: stackoverflow.com/questions/9287450/… Jul 16, 2014 at 10:06
  • 4
    Caution! wmic diskdrive get serialnumber (and the Win32_DiskDrive WMI class in general) returns the serial number with each pair of characters reversed. So if your hard drive label reads "abcd1234" WMI will report your serial number as "badc2143". More information here.
    – rojo
    Dec 4, 2014 at 21:11
8

In the same vein as Moab's answer, but using PowerShell this time:

Get-CimInstance Win32_DiskDrive | Select-Object Model,SerialNumber

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.

This answer assumes PowerShell 3.0 or later. If running an older version, use Get-WmiObject in place of Get-CimInstance.

On Windows 8 and later, you can also use this command:

Get-PhysicalDisk | Select-Object FriendlyName,SerialNumber
1
  • Doesn't work for NVMe drives. I am guessing NVMe drives just don't expose their serial at all. For NVMe drives, WMI reports a long number which in no way matches any part of the serial on the physical label. Apr 12, 2021 at 21:13
6
  • What you are looking at is NOT the hard drive serial number.

  • It is called the Volume Serial Number. It is generated at the time of creating and formatting the volume / partition.

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

  • All you can do is redirect the output of that command to a file : C:\> vol c: > myvol.txt and it will be stored as a text file in your C:

  • I am attaching a screenshot with the highlights:

enter image description here

  • The file was stored in the root of C:

enter image description here

  • This is what the myvol.txt file looks like in Notepad:

enter image description here

3
  • Question edited; sorry for the mis-information Nov 2, 2012 at 16:39
  • 1
    Before considering a down vote to this answer, please note that it was posted before the OP clarified the original question. This answer was indeed correct for the original question. Feb 11, 2018 at 18:01
  • serial numbers retrieved this way do not match the serial numbers in SeaTools for Windows???
    – oldboy
    May 25, 2019 at 2:08
6

In a batch file one approach is:

  1. VOL command to produce the serial number as text along with text we don't want.
  2. FIND to trim it down to only the line with the serial number.
  3. FOR to grab the 5th token (a part between delimiters) on the line with the serial number.
  4. SET to assign to an environment variable

for /f "tokens=5 delims= " %%a in ('vol c: ^| Find "Serial Number"') do (
set VOLSERIAL=%%a
)
3
  • Question edited; sorry for the mis-information Nov 2, 2012 at 16:33
  • 2
    Before considering a down vote to this answer, please note that it was posted before the OP clarified the original question. This answer was indeed correct for the original question. Feb 11, 2018 at 18:03
  • I used this method to easily identify hard disks and drive letter mappings in a cmd batch file. Thank you for sharing! Sep 12, 2020 at 18:48
0

Get the "windows serial number" from powershell:

(-split (cmd /c vol c: | select-string serial))[4]

G92B-EC00

Alternatively,

get-ciminstance Win32_LogicalDisk | % VolumeSerialNumber

G92BEC00
1
  • That’s cool and all (there’s probably a more PS-y way), but: “The one I'm looking at is the serial number of the physical hard disk drive”
    – Daniel B
    Jan 27, 2020 at 20:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .