Tested under Windows 10 only, this works well for non-OEM:
(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey
and this appears to be good for OEM/sticker:
(GCIM SoftwareLicensingService).OA3xOriginalProductKey