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?
5 Answers
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!
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.
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.
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!
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!
I tried that too, but it still just gives me the fake serial. I also tested out the Win32_DiskDrive class.