Windows Product key can be retrieved using PowerShell or CMD. To retrieve the product key using PowerShell, we need to query SoftwareLicesingService class and there is a property called OA3xOriginalProductKey which stores the product key.
Get-WmiObject -query `select * from SoftwareLicensingService' | Select OA3xOriginalProductKey
OA3xOriginalProductKey ---------------------- BBBBB-CSDSC-EESSR-KKIDS-AAAAA
We can also query this WMI class using cmd as shown below.
wmic path softwarelicensingservice get OA3xOriginalProductKey
Caution: It may or may not work for all the Windows OS. The above is tested in Windows 10.