How to get Microsoft Office product key without using third party software

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.

  1. Open Notepad.
  2. 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
    }
    
  3. 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".office key
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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

    Press Enter to allow the execution policy to be changed. Windows PowerShell

  9. 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.

  10. Voila, your Office product key will be displayed on the screen!

Thanks to our reader "bosbigal" for sharing this script.

27 thoughts on “How to get Microsoft Office product key without using third party software

  1. Phil

    i move away from crap OS
    i moved to Linux Lite OS
    http://i.imgur.com/YG77oKs.png

    Reply
    1. Sergey Tkachenko Post author

      Which distro?

      Reply
      1. Phil

        linuxliteos.com

        Reply
        1. Sergey Tkachenko Post author

          Ah, so you are using XFCE4 now :)

          Reply
          1. Phil

            yup

    2. Barry Frost

      you can try KeyGetter, pretty useful tool for this

      Reply
  2. Steve

    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.

    Reply
  3. Juliano

    The key result is diferent from key installed?
    Why?

    Reply
    1. Sergey Tkachenko Post author

      for which edition of MS Office?

      Reply
  4. Rob

    Didn’t work for me on Win 10, I followed the steps accurately

    Reply
  5. James

    As many others have commented, this script doesn’t work at all with Windows 10.

    Reply
  6. dan

    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
    }

    Reply
    1. Keytrap

      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-–) {

      Reply
  7. Susie

    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

    Reply
  8. Mike

    Worked great for me on a Surface Pro running Windows 10 64-bit Office 2016 standard. Thanks.

    Reply
    1. Sergey Tkachenko Post author

      Don’t mention it.

      Reply
  9. Mees

    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?

    Reply
  10. JoCo

    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

    Reply
  11. TomW

    Windows 7 64bit + Office 2016 64bit – script not work :(

    Reply
  12. mark applier

    for w1064bit creators it doesnt work
    it doesnt yeld anything after the import

    Reply
  13. mark applier

    I ran it again in powershellX86 and it yelded a key for an unknown ( blank ) ms product that i never used…

    Reply
  14. Anonymous Coward

    This script does not work. I’m using Windows 10 on 64-bit hardware with MS-Office 2016.

    Reply
  15. Ivan Montilla Miralles

    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.

    Reply
  16. Steve

    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?

    Reply
    1. Em

      Go back to the steps – you did not change the username in the path to match your computer.

      Reply
  17. Em

    Worked perfect for me on Windows 10, 32 bit version of office 2010. Lifesaver – thanks!

    Reply
  18. Another IT Guy

    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.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.