If you have lost your Microsoft Office product key or forgotten where you had stored it and can no longer retrieve it, do not despair. I would like to share a simple solution to extract your Office product key from the OS installed on your PC without using any third party software.
- Open Notepad.
- Copy and paste the following text into the Notepad window
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 }
- Save the text above into a file with the ".ps1" extension on the Desktop.
Bonus tip: To make sure that you save the file correctly with the ".ps1" extension, you can type its name in double quotes, for example, "office.ps1". - Now you must determine if you have a 32-bit version of Office or 64-bit. If you have Office 2007, 2003 or earlier, then you have a 32-bit version as there was no 64-bit version released. Also, if your Windows is 32-bit, then your Office is also 32-bit because 64-bit apps cannot run on 32-bit Windows.
- If you have 64-bit Windows and if you run Office 2010, 2013 or 2016, it can either be 32-bit or 64-bit. To determine this, start any Office application such as Word, OneNote, Excel etc.
- Click File and then Help in the File menu. On the right, under the About... section, you will see it listed whether it's 32-bit or 64-bit.
- Now you must open Powershell as administrator. If you are running 32-bit Office, open the 32-bit version of PowerShell. If you are running 64-bit Office, open 64-bit PowerShell. Type "powershell" into the search box of the Start Menu or right on the Start Screen. On 64-bit Windows, the shortcut named 'Windows PowerShell (x86)' is the 32-bit version of PowerShell and the one without 'x86' in its name is the 64-bit PowerShell. Right click it and choose Run as administrator or select the correct shortcut with the keyboard and press CTRL+SHIFT+Enter. This will open an elevated PowerShell window.
- Enable the execution of local files which are not digitally signed. This can be done with the following command (you can copy-paste it):
Set-ExecutionPolicy RemoteSigned
- Now you should type the following command:
Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey
Note: You must change the path in the command above, including your user name folder, to correctly point to the location where you saved the office.ps1 file.
- Voila, your Office product key will be displayed on the screen!
Thanks to our reader "bosbigal" for sharing this script.
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:
i move away from crap OS
i moved to Linux Lite OS
http://i.imgur.com/YG77oKs.png
Which distro?
linuxliteos.com
Ah, so you are using XFCE4 now :)
yup
you can try KeyGetter, pretty useful tool for this
Didn’t work for me. Using Windows 7 Pro, 64-bit Office 2016, 64-bit Powershell in Admin Mode, Ran both commands, no output on second one with the key. Thanks anyway.
The key result is diferent from key installed?
Why?
for which edition of MS Office?
Didn’t work for me on Win 10, I followed the steps accurately
As many others have commented, this script doesn’t work at all with Windows 10.
It worked for me, but mine was in the WOW6432 folder, so I modified the code to just look at that one entry.
Here is the resulting code:
function Get-MSOfficeProductKey {
$hklm = 2147483650
$wmi = [WMIClass]”\\.\root\default:stdRegProv”
$data = $wmi.GetBinaryValue($hklm,”SOFTWARE\WOW6432Node\Microsoft\Office\14.0\Registration\{90140000-0012-0000-0000-0000000FF1CE}”,”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
}
}
$productKey
}
Replace for ($i = 24; $i -ge 0; $i–) {
by for ($i = 24; $i -ge 0; $i–-) {
and replace for ($i = 24; $i -ge 0; $j–) {
by for ($i = 24; $i -ge 0; $j-–) {
I tried this method both with the original code given, as well as dan’s modified code and it just gave me varying lengths of error messages, the gist of which is:
You must provide a value expression following the ‘-‘ operator
The term ‘Get-MSOfficeProductKey’ is not recognized as the name of a cmdlet, function, script file, or operable program
Worked great for me on a Surface Pro running Windows 10 64-bit Office 2016 standard. Thanks.
Don’t mention it.
This worked for a Windows 10 computer, but it pulled my Office 2007 (wow, didn’t even know I had it!) product key. I wonder how I could modify this to find my Office 2016 key?
I needed to recover a key off my other computer so I tested it on my main computer first that I know the product key for office to see if it works.
I did get a product key display in powershell but it is not the same key that I activated my office with.
I am using windows 10(creators update) x64 and Office 2013 x64
Windows 7 64bit + Office 2016 64bit – script not work :(
for w1064bit creators it doesnt work
it doesnt yeld anything after the import
I ran it again in powershellX86 and it yelded a key for an unknown ( blank ) ms product that i never used…
This script does not work. I’m using Windows 10 on 64-bit hardware with MS-Office 2016.
Good evening,
The script worked just fine for me. Windows 8.1 with 64 bit Office 2016 Professional. This saved my day and I’m grateful to you.
Hope you have a great weekend.
When I copy and paste Set-ExecutionPolicy RemoteSigned here’s what I get:
PS C:\windows\system32> Set-ExecutionPolicy RemoteSigned
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”):
[[ NOTE : The [N] No is highlighted in stead of the [Y] Yes ]]
PS C:\windows\system32> Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey
Import-Module : The specified module ‘C:\Users\Winaero\Desktop\office.ps1’ was not loaded because no valid module file
was found in any module directory.
At line:1 char:1
+ Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProduc …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (C:\Users\Winaero\Desktop\office.ps1:String) [Import-Module], FileNo
tFoundException
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Get-MSOfficeProductKey : The term ‘Get-MSOfficeProductKey’ 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 try again.
At line:1 char:52
+ … rt-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-MSOfficeProductKey:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\windows\system32>
What should I do?
Go back to the steps – you did not change the username in the path to match your computer.
Worked perfect for me on Windows 10, 32 bit version of office 2010. Lifesaver – thanks!
Hi all, it took me a while to get this working. Since I didn’t follow the instructions exactly and didn’t run the 32bit version of power-shell for my W10 64bit, office 2010 32bit recovery.
Spend a lot of time messing with the WOW6432 which wasn’t necessary as it automatically searched part of the registry when I ran the 32bit version of powershell.
Also I noticed the default execution policy was No. So pressing enter may have NOT Applied the policy.
Two questions:
1- input the right path ..if i have the file on my desktop, which are the proper words to write?
2- how to handle this message “The term ‘Get-MSOfficeProductKey’ 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”?
Thanks
It didn’t work for me and I tried it a few times
Sorry but this didn’t work also for me :-( …
Win10 64 bit
Office 2016 32bit
i’m not into w scripting, but, for what i understand, the script searches the registry for some
“DigitalProductId” string/key … i have NOT found such a key in my registry
thank you anyway, cheers
Returns nothing on Win10-64 with Office 2013… Unfortunately!