1

I run below command in cmd in Windows:

wmic diskdrive get serialnumber

which gives me the following result:

SerialNumber
W2B0MMLM
S2SMJ9DD906854

What if I only want primary harddisk's serial number only?

4
  • 1
    You pipe the result into something like Select-Object where you then "select" the HDD you are interested in. You can also use the where clause based on the ID of the HDD.
    – Ramhound
    Sep 21 '17 at 19:01
  • @Ramhound I am currently developing an application which will run on some other computer(s). I want to collect the primary harddisk serial number from that computer. So, how can I use ID in that case?
    – Vishal
    Sep 21 '17 at 19:03
  • You have to determine which is the first physical disk, I might have read the answer incorrectly, but I sort of assumed it was going to match PHYSICALDRIVE0 or something similar. However, would like to point out by advice is still sound, pipe or where clause would be what you would need to use.
    – Ramhound
    Sep 21 '17 at 19:09
  • @Ramhound I got the result by using this command: wmic path win32_physicalmedia where tag='\\\\.\\PHYSICALDRIVE0' get serialnumber /format:list Now I want to remove the word SerialNumber from output. Is it possible to specify in commmand?
    – Vishal
    Sep 21 '17 at 19:38
1

You could try this:

wmic logicaldisk where (DeviceID="C:") assoc /assocclass:Win32_LogicalDiskToPartition

With this command you get the partition id ("Disk #0, Partition #0"). (If you have the system installed on C drive. You can change the letter anytime)

wmic partition where (DeviceID="Disk #0, Partition #0") assoc /assocclass:Win32_DiskDriveToDiskPartition

With this command you get the physical drive id ("\\.\PHYSICALDRIVE0")

wmic path win32_diskdrive where deviceid='\\\\.\\PHYSICALDRIVE0' get serialnumber

With this you get the serial number of the primary hard disk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.