If you lost, cannot retrieve or forgot where you had stored the product key of your Windows 8.1, Windows 8 or Windows 7 OS, do not despair. I would like to show you a simple solution to extract your product key from the OS installed on your PC without using any third party software.
Advertisеment
- Open Notepad.
- Copy and paste the following text into the notepad window
function Get-WindowsKey { ## function to retrieve the Windows Product Key from any PC ## by Jakob Bindslet (jakob@bindslet.dk) param ($targets = ".") $hklm = 2147483650 $regPath = "Software\Microsoft\Windows NT\CurrentVersion" $regValue = "DigitalProductId" Foreach ($target in $targets) { $productKey = $null $win32os = $null $wmi = [WMIClass]"\\$target\root\default:stdRegProv" $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue) $binArray = ($data.uValue)[52..66] $charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9" ## decrypt base24 encoded binary data For ($i = 24; $i -ge 0; $i--) { $k = 0 For ($j = 14; $j -ge 0; $j--) { $k = $k * 256 -bxor $binArray[$j] $binArray[$j] = [math]::truncate($k / 24) $k = $k % 24 } $productKey = $charsArray[$k] + $productKey If (($i % 5 -eq 0) -and ($i -ne 0)) { $productKey = "-" + $productKey } } $win32os = Get-WmiObject Win32_OperatingSystem -computer $target $obj = New-Object Object $obj | Add-Member Noteproperty Computer -value $target $obj | Add-Member Noteproperty Caption -value $win32os.Caption $obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture $obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber $obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser $obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber $obj | Add-Member Noteproperty ProductKey -value $productkey $obj } }
- Save the text above into a file with the ".ps1" extension on the Desktop.
Bonus tip: To make sure that you saving the file with the ".ps1" extension, you can type its name with double quotes, for example, "GetProductKey.ps1". - Open the Powershell console as administrator by typing "powershell" in the search box of the Start Menu or right on the Start Screen and then press CTRL+SHIFT+Enter. This will open the elevated Powershell window.
- Enable the execution of local files which are not digitally signed. This can be done with the following command:
Set-ExecutionPolicy RemoteSigned
- Now you should type the following command:
Import-Module C:\Users\Winaero\Desktop\GetProductKey.ps1; Get-WindowsKey
Note: Change the path to the GetProductKey.ps1 file in the command above, according to the location where you saved it.
- Voila, you product key is displayed on the screen!
See the following video if you have any questions:
Support us
Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:
If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!
Advertisеment
WoW! Thanks so perfect…
but I have a little issue with finding my original product keys. i have an old PC where the original keys which is usually written @ the bottom of the PC has been wiped out. Is there anyway I can get that? i need it so that I can get back my original and genuine os which came as preinstalled on my PC. thanks
In your case, you should contact your PC manufacturer. This is only way for damaged stickers.
On a related note, can you make a tutorial on how to make a back-up of activation of Windows 7/8 without using any third-party utilities? It’ll definitely come in handy for those people who would like to re-install Windows without going to the trouble and messy process of re-activation.
Anyway, thanks for this awesome tutorial!
That. Was pretty sweet, thanks a lot.
^^ you are welcome
I get an error after trying to change the execution policy change: access is denied… Set-executionpolicy <<<< remotesigned… Categoryinfo : notspecified [set-executionpolicy], unauthorised access exception… Fullyqualifiederrorid : system.unauthorisedaccessexception,microsoft.powershell.commands.setexecutionpolicycommand
Help please!
It loks like you tried to run the command in the regular Power Shell. Please use the elevated instance, it will resolve your issue.
Hello, i have a problem with this tutorial, it shows me a error:
Get-WmiObject : invalid class
At c:#users#romas#desktop#getproductkey.ps1:28 char:33
+ $win32os = get-wmiobject <<<< Win32_operatingsystem -computer $target
+ categoryinfo :invalidoperation: (:) [get-wmiobject], managementexception
+ fullyqualifiederrorid : getwmimanagementexception, microsoft.powershell. commands. getwmiobjektcommand
I use Windows PowerShell (x86)
Maybe You can help me :-)
Are you sure that you run PS as admin?
yes
Hmm, I have no idea.
Really.
ther is a other error :
cannot index into a null array.
at c:\users\romas\deskot\getproductkey.ps1: 19 char:47
+$k = $k*256 -bxor $binarray[ <<<< $j]
+categoryinfo :invalidoperation: (0:int32) [], runtimeexception
+fullyqualifiederrorid: nullarray.
and second error in the same time is:
cannot index into a null array.
at c:\users\romas\deskot\getproductkey.ps1: 20 char:27
+$binarray[ <<<<$j] = [math]]::truncate{$k/24)
+categoryinfo :invalidoperation: (0:int32) [], runtimeexception
+fullyqualifiederrorid: nullarray
Is there anyway to use that same solution for getting the Exchange 2010 CD-Key that was used for the install? I can get the product id very easily but not he CD-Key.
Thanks,
Robert
I have no idea, I am not a user of Exchange 2010.
By far the best method I’ve seen. Priceless!
I am not certain of this yet because I am still int he process of investigating it, but I do believe the encode method for DigitalProductId has changed in Windows 8 and 8.1. I have created two others in VBS and VB.NET and neither of those will work on my windows 8.1 either, but work fine on the XP. I downloaded Magic Jelly Bean and Belarc and both of those and both of mine match up fine with the XP, but mine do not work on the 8.1…Jelly Bean and Belarc does!
Anyway if that is the case and you come across the correct decoding process could you please email me and let me know…i have several pieces of software that are useless now and I can not find information online anywhere concerning the correct encoding that was used on 8 and 8.1
Thanks
Brandon
pinnickbrandon@live.com
Thanks for this niffty tool. Two notes: In step 5 i used,
Set-ExecutionPolicy RemoteSigned -Scope Process
to limit the policy change to the current power shell session.
The computer name shows as “.” ignoring the actual name.
I got every step right and even got the product key… I entered it still it says that the product key you have entered does not appear to be a valid windows 7 product key.
Please Help
My screen shows B’s for the Product Key:
BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
Any thoughts on whats going on?
Mike
Cool, you have a lucky serial number :D
Seriously, I have no idea.
I just had the same issue and apparently:
Some editions of Windows (and some other Microsoft products) are made available via what’s called a “volume license.” In these types of distributions, a product key is shared among anywhere from five to hundreds or thousands of software installations, depending on the license, so product verification is handled differently.
Basically, this means that your product key is not stored in the registry and no product key finder program will be able to find it. You can’t find something that isn’t there. Your best bet in this situation is to contact the provider of your copy of Windows and ask for a replacement product key.
Which makes sense in my situation
hope this helps
thank you for your comment
Well, there are two version of the volume activation: Volume MAK and Volume KMS. For MAK installations there must be a key somewhere, as the command “slmgr.vbs /dlv” shown the last portion of the installed key. The same goes basically for KMS installations, but these product keys are public anyway: https://technet.microsoft.com/en-us/library/jj612867.aspx
Change DigitalProductId to DigitalProductId4 in this line below. Works for Enterprise versions.
$regValue = “DigitalProductId”
Change to
$regValue = “DigitalProductId4”
The key generated script of not correct .
works for ms offfice to but with this script
just change to
Import-Module C:\Users\Winaero\Desktop\GetProductKey.ps1; Get-MSOfficeProductKey
function Get-MSOfficeProductKey {
param(
[string[]]$computerName = “.”
)
$product = @()
$hklm = 2147483650
$path = “SOFTWARE\Microsoft\Office”
foreach ($computer in $computerName) {
$wmi = [WMIClass]”\\$computer\root\default:stdRegProv”
$subkeys1 = $wmi.EnumKey($hklm,$path)
foreach ($subkey1 in $subkeys1.snames) {
$subkeys2 = $wmi.EnumKey($hklm,”$path\$subkey1″)
foreach ($subkey2 in $subkeys2.snames) {
$subkeys3 = $wmi.EnumKey($hklm,”$path\$subkey1\$subkey2″)
foreach ($subkey3 in $subkeys3.snames) {
$subkeys4 = $wmi.EnumValues($hklm,”$path\$subkey1\$subkey2\$subkey3″)
foreach ($subkey4 in $subkeys4.snames) {
if ($subkey4 -eq “digitalproductid”) {
$temp = “” | select ComputerName,ProductName,ProductKey
$temp.ComputerName = $computer
$productName = $wmi.GetStringValue($hklm,”$path\$subkey1\$subkey2\$subkey3″,”productname”)
$temp.ProductName = $productName.sValue
$data = $wmi.GetBinaryValue($hklm,”$path\$subkey1\$subkey2\$subkey3″,”digitalproductid”)
$valueData = ($data.uValue)[52..66]
# decrypt base24 encoded binary data
$productKey = “”
$chars = “BCDFGHJKMPQRTVWXY2346789”
for ($i = 24; $i -ge 0; $i–) {
$r = 0
for ($j = 14; $j -ge 0; $j–) {
$r = ($r * 256) -bxor $valueData[$j]
$valueData[$j] = [math]::Truncate($r / 24)
$r = $r % 24
}
$productKey = $chars[$r] + $productKey
if (($i % 5) -eq 0 -and $i -ne 0) {
$productKey = “-” + $productKey
}
}
$temp.ProductKey = $productKey
$product += $temp
}
}
}
}
}
}
$product
}
Got in a bit of trouble actually veiwing websites on my laptop so I had to type this up manually and after some minor errors in the first draft it thankfully it spat out some details for me anyways on this line “$obj | Add-Member Noteproperty ProductKey -value $productkey” “$productkey” should be “$productKey” also the script processor whined about there being an “and” in the “If” (could be a case sensitive thing I dunno) so I split the “-ne” and “-eq” checks and put it as a nested “If” anways regardless of whether the key works or not thank you as this was a but if fun and of course my key actually does work then job done lol
I have been searching for this technique for years, and have even purchased two copies of RecoverKeys in the past when I couldn’t make any of the other techniques I’d find online work. This one worked properly the first time. Thank you very much for sharing this. It literally just saved me $25. I appreciate it.
-Zac
Very nice :)
Thanks! This worked like a charm on my ASUS running Windows 8.1.
Glat to hear
For some reason this doesnt seem to work in windows 7 professional. Windows 7 ultimate it’s working fine.
I get the following error:
The term ‘Get-WindowsKey’ is not recognized as the name of a cmdlet, function, script fi
le, or operable program. Check the spelling of the name, or if a path was included, veri
fy that the path is correct and try again.
help plz!
Well, check the spelling of the name, or if a path was included, verify that the path is correct and try again.
how about this
1. hold the window button press r , type “regedit” then enter key or ok button.
2. registry editor opens, in it press f3 and type “DigitalProductId” in the search box, bang the enter key
3. on the right, where it found it you will see “ProductId” , a registry key,
4. double click on it
No Good!
Product ID comes up encoded, not in clear text.
Any idea how i could run this script to query remote machines?
Now that I am looking at the code, I see the $targets variable. Could I pass a comma separated list instead of referencing =”
.”?
So, I tried to specify $targets as more than 1 machine like this
param ($targets = “SERVER1,SERVER2,SERVER3”)
and I got a ton of powershell errors saying the following
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (14:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (14:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (13:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (13:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (12:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (12:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (11:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (11:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (10:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (10:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (9:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:20 char:27
+ $binArray[ <<<< $j] = [math]::truncate($k / 24)
+ CategoryInfo : InvalidOperation: (9:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Cannot index into a null array.
At \\server1\it\Backups\Scripts\Install\Get_Windows_Product_key.ps1:19 char:47
+ $k = $k * 256 -bxor $binArray[ <<<< $j]
+ CategoryInfo : InvalidOperation: (8:Int32) [], RuntimeException
and it just keeps going and going…
Please clue me into how to run this power shell script against multiple machines.
The script show a different key than Produkey. ProduKey has the correct one. I know because I entered it. Running 8.1 Pro 64 bit.
Invalid result on server 2012 –
ProductKey : BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
same result on Server 2012
ProductKey : BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
Thanks so much.
This grabbed the wrong key for my machine, unfortunately. It wouldn’t activate. I tried ProduKey by NirSoft (it was the only one I could find without bundled crapware) and it found another key that did work. I’m guessing this script is close, but needs a tweak?
I concur… on Server 2012 R2 I get different results than the keys I know I’ve used. Using Nirsoft’s ProduKey returns correct results.
Does not work on Windows 10. Decryption method is wrong. Apparently, Microsoft no longer uses base24 since Windows 8?
Please refer to the following article
https://winaero.com/blog/how-to-view-your-product-key-in-windows-10-windows-8-and-windows-7/
It works for me, in my Windows 10 10240 Pro
Thanks, this script work fine in Windows 7 Home Premium
– Caption : Microsoft Windows 7 Home Premium
– CSDVersion : Service Pack 1
– OSArch : 64 bits
– BuildNumber : 7601
(Report from MGADiag.exe)
– Windows License Type: COA SLP
– Windows OS version: 6.1.7601.2.00010300.1.0.003
after running this scrip product key shows like.
BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
can yo help me to ckear this issue.i need that product key..
i have tried 3 script by search in google.for all am getting that above mentioned key.
pls help me to solve this issue.
Anyone who gets multiple B’s as product key:
$regValue = “DigitalProductId” is looking to the wrong place this is the only piece you need to change and you need to change it to $regValue = “DigitalProductId4”
does it work in windows 10 rtm?
Yep
thank you
http://i.imgur.com/hMAhlnp.jpg
recently upgraded from 8.1 update to 10 rtm because I have reserved to get windows 10 rtm last time
Try to set the policy like this
Set-ExecutionPolicy Unrestricted
and then re-run the script
sorry for extremely late reply, it’s working!
http://i.imgur.com/vueTdvK.png
I’m receiving this message… what to do?
cmdlet import-Module at command pipeline position 1
supply values for the following parameters:
Name[0];
i face this error
Import-Module : The specified module ‘C:\Users\Winaero\Deskttop\GetProductKey.ps1’ was not loaded becau
le file was found in any module directory.
At line:1 char:14
+ Import-Module <<<< C:\Users\Winaero\Deskttop\GetProductKey.ps1;
+ CategoryInfo : ResourceUnavailable: (C:\Users\Winaer…tProductKey.ps1:String) [Import-M
FoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Correct this path: C:\Users\Winaero\Deskttop
That path is on MY computer.
Thanks a lot !!!
Every time I run this script or other scripts I have found.
My product key always shows up as all B’s.
Would anyone know why that is?
Computer : .
Caption : Microsoft Windows 7 Professional
CSDVersion : Service Pack 1
OSArch : 64-bit
BuildNumber : 7601
RegisteredTo :
ProductID : 55041-148-1169542-86371
ProductKey : BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
What if *ALL* the product keys are the same? I have several machines, all upgraded from Windows 7 to 10…
The key this script gives may be valid, but I’m getting the EXACT SAME key information for ALL the PCs that have been upgraded. We do not have volume licensing and all my Windows 7 keys are different. The SAME Windows 10 key given by the script does not match any of the original Windows 7 script keys.
So is Microsoft issuing everyone the same key for the free Windows 10 upgrade period? AND — My Horror which is why I’m trying to gather the information. What happens this August 2016 when Windows 10 is no longer a “free upgrade” and I loose a hard drive, or have a virus and have to bare metal reload?
I was told by Microsoft directly that I would have to load my OLD WINDOWS OS *FIRST* and then re-run the upgrade procedure as I couldn’t just load 10.
When Windows 10 isn’t FREE anymore, will you then have to buy it for one of these situations?
Provided method doe not work with enterprise versions
Computer : .
Caption : Microsoft Windows 10 Enterprise
CSDVersion :
OSArch : 64-bit
BuildNumber : 10586
RegisteredTo : Nowokalone
ProductID : 00329-10330-00000-AA737
ProductKey : BBBBB-BBBBB-BBBBB-BBBBB-BBBBB
Worked like a charm!
Thanks a bunch,
Bary
It shows BBBBB-BBBBB-BBBBB-BBBBB-BBBBB as a serial number
Worked perfectly Thanks. I had virtualized the server had the key was long gone!.
This error came after windows update. This is a new way for Microsoft to get money from users.
This gives wrong Key. After receiving the Key from this script, compare it with the last part of the key retrieved by the command slmgr /dli . The script gives wrong Key.
FASI
Hi ,
I am facing this error.
PS C:\Users\Administrator> Import-Module C:\Users\Administrator\Desktop\GetProductKey.ps1; Get-WindowsKey
Import-Module : The specified module ‘C:\Users\Administrator\Desktop\GetProductKey.ps1’ was not loaded because no
valid module file was found in any module directory.
At line:1 char:1
+ Import-Module C:\Users\Administrator\Desktop\GetProductKey.ps1; Get-WindowsKey
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\Admini…tProductKey.ps1:String) [Import-Module], File
FoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Get-WindowsKey : The term ‘Get-WindowsKey’ is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and tr
again.
At line:1 char:65
+ Import-Module C:\Users\Administrator\Desktop\GetProductKey.ps1; Get-WindowsKey
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-WindowsKey:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Thats awesome dude !! You are a genius !!