Windows License Extractor is a small PowerShell/WinForms GUI tool (Sapien PowerShell Studio 2015) that will help you to display/export licensing information (including the product key where possible) for your current running operating system, as well as other remote computers.

 
 
 
 
 

It can be run against a multiple remote machines in bulk and export the collected data into CSV file:

This utility can be useful if you lost the product key of your Windows, and you want to reinstall it on your computer.
Note that if the Windows product key is not stored in the Registry (like in volume licenses) it will be displayed partially.

Code Snippet:

Try 
            { 
                #License Info 
                $LicenseInfo = Get-WmiObject SoftwareLicensingProduct -ComputerName $target -Credential $cred -ErrorAction Stop | ` 
                Where-Object { $_.PartialProductKey -and $_.ApplicationID -eq "55c92734-d682-4d71-983e-d6ec3f16059f" } | Select-Object PartialProductKey, Description, ProductKeyChannel, @{ N = "LicenseStatus"; E = { $lstat["$($_.LicenseStatus)"] } } 
                $win32os = Get-WmiObject Win32_OperatingSystem -computer $target -Credential $cred -ErrorAction Stop 
                $WindowsEdition = $win32os.Caption 
                $ServicePack = $win32os.CSDVersion 
                $OSArchitecture = $win32os.OSArchitecture 
                $BuildNumber = $win32os.BuildNumber 
                $RegisteredTo = $win32os.RegisteredUser 
                $ProductID = $win32os.SerialNumber 
                $PartialProductKey = $LicenseInfo.PartialProductKey 
                If ($LicenseInfo.ProductKeyChannel) 
                { 
                    $LicenseType = $LicenseInfo.ProductKeyChannel 
                } 
                Else 
                { 
                    $LicenseType = $LicenseInfo.Description.Split(",")[1] -replace " channel", "" -replace "_", ":" -replace " ", "" 
                } 
                $LicenseStatus = $LicenseInfo.LicenseStatus 
            }

 

 
Verified on the following platforms
Windows 10 Yes
Windows Server 2012 Yes
Windows Server 2012 R2 No
Windows Server 2008 R2 Yes
Windows Server 2008 Yes
Windows Server 2003 No
Windows Server 2016 No
Windows 8 Yes
Windows 7 Yes
Windows Vista No
Windows XP No
Windows 2000 No
This script is tested on these platforms by the author. It is likely to work on other platforms as well. If you try it and find that it works on another platform, please add a note to the script discussion to let others know.