1

I know I can get the serial number of all listed hard drives by using:

wmic diskdrive list brief

or specifically

wmic diskdrive get serialnumber

And I can get the drive letter from the logical disk:

wmic logicaldisk list brief

or specifically

wmic logicaldisk get deviceid

But how do I correlate the drive letter (logicaldisk DeviceID) with the physical disk ID (diskdrive DeviceID)? I'd like to do this from command line in a batch file if at all possible.

0

3 Answers 3

2

I found a solution for that, if anyone needs it in the future:

Get-Partition -DriveLetter "C" | Get-Disk | Select-Object Serialnumber | ForEach {$_.SerialNumber}

This select the partition "C" and use the Get-Disk too get the serial number and then it select the object with serial number. Since there's only one object the ForEach will give you the serial number only!

It cost me a while to get this working, hope this will save some people some hours of their life time...

1

You can find GUID of disk using diskpart:

Start>run>cmd>diskpart>list disk and check for GPT

Start>run>cmd>diskpart>list disk>select disk> uniqueid disk and check for disk ID

You could also use the command mountvol C:/ /L to obtain the GUID of this partition.

1
  • Thanks. I am trying to automate it. If I provide the drive letter, I want to be able to get the serial number.
    – HTWingNut
    Commented May 5, 2021 at 21:32
1

Since your solution is for PowerShell, here is another way to get it for all Disks at once:

GWMI -namespace root\cimv2 -class win32_volume | FL -property DriveLetter, DeviceID, SerialNumber
2
  • Which solution ?
    – Toto
    Commented May 5, 2023 at 13:46
  • The serial number this outputs is the volume's serial number, not the hard drive's Commented Sep 4, 2023 at 1:55

You must log in to answer this question.

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