The code works fine (been using this in my inventory script for months now).
What this does, it retrieves the OEM product key which is imprinted in the BIOS.
This only works on Windows 10 and only on OEM machines such as HP, Dell, Lenovo etc.
For some machines you have to have the latest BIOS version for it to work.