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
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.
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.
On Windows 8 and later, you can also use this command:
Get-PhysicalDisk | Select-Object FriendlyName,SerialNumber
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.txtand it will be stored as a text file in your
I am attaching a screenshot with the highlights:
- The file was stored in the root of
- This is what the
myvol.txtfile looks like in Notepad:
In a batch file one approach is:
- VOL command to produce the serial number as text along with text we don't want.
- FIND to trim it down to only the line with the serial number.
- FOR to grab the 5th token (a part between delimiters) on the line with the serial number.
- SET to assign to an environment variable
for /f "tokens=5 delims= " %%a in ('vol c: ^| Find "Serial Number"') do ( set VOLSERIAL=%%a )