How can I get the correct NVMe serial number using PowerShell?
Asked by
sugar-crystal growth
I'm struggling to get the actual NVMe serial number for my SSDs using PowerShell. When I run the command `(Get-PhysicalDisk).AdapterSerialNumber`, it often returns a blank value on some of my Dell machines, while using `SerialNumber` provides a misleading format like `E823_8FA6_BF53_0001_001B_448B_4BAB_1EF4`. I know that CrystalDiskInfo retrieves the correct serial number without any issues, but with various SSDs in these machines, I can't rely on any specific manufacturer's tools for info. Interestingly, the Intel Optane Memory and Storage Management tool correctly shows the serial number, but in the Controller Serial Number field. I spent hours trying different methods and even switched from RAID to AHCI settings, both without success. Does anyone have a reliable way to programmatically obtain the NVMe serial number?
Answers
I ran a test similar to yours and found that using `Get-PhysicalDisk | select friendlyname, serialnumber, AdapterSerialNumber` didnโt yield the results I hoped for. It's true that the RAID setup could affect the outcome, but since you already switched, there might be more going on. Keep pushing โ itโs a tough nut to crack!
Reply to this answer
Youโre correct that some programs like CrystalDiskInfo get the serial number by sending commands directly to the device rather than through Windows enumeration. Check out the WinAPI documentation for DeviceIoControl; that might lead you to the solution you're looking for. As a heads up, there are known inconsistencies when fetching serial numbers this way, so donโt get discouraged!
Reply to this answer
You might want to try using `Get-CimInstance -ClassName Win32_PhysicalMedia | Select-Object Tag,SerialNumber`. It can sometimes yield better results than the usual command. Though I understand it can still return incorrect values in some cases.
Reply to this answer
If you need a physical hardware serial number, running `vol` in CMD wonโt help, since it gives you just the logical volume serial number. Youโre looking for something deeper than that.
Reply to this answer
You might want to dig into using the DeviceIoControl native API with P/Invoke in C#. It could provide the access you need to read the hardware serial number directly. There are some good C# examples online that might help you get started!
Reply to this answer
Add your answer
Answers are reviewed before publication.
sugar-crystal growth: I tried that too, but it still just gives me the fake serial. I also tested out the Win32_DiskDrive class.