Get product keys of local and remote systems

This is an updated version of the Get-ProductKey function that was featured on's PowerTips. This function expands on the existing code by allowing the querying of multiple remote systems, outputting of objects that include the system, Operating System and version

3.7 Star
178,022 times
Add to favorites
Operating System
E-mail Twitter Digg Facebook
  • For Windows 7, 8, 8.1 followng code works:
    2 Posts | Last post June 24, 2017
    • function GetDepreciatedOS_PK()
         $TrTable = "BCDFGHJKMPQRTVWXY2346789"
         $path    = "\SOFTWARE\Microsoft\Windows NT\CurrentVersion" 
         $IntArr  = ( get-itemproperty HKLM:\"$path" -Name 'DigitalProductId' ).DigitalProductId
         $isWin8  = (  ( ( $IntArr[ 66 ] -band 0xFF ) %  6 ) -band 1 )
         $IntArr[ 66 ] = ( $IntArr[ 66 ] -band 0xF7 ) -bor ( ( $isWin8 -band 2 ) * 4 )  
         $TrTable = "BCDFGHJKMPQRTVWXY2346789";  
         $PK      = "";  
         for ( $i = 24; $i -ge 0; $i-- ) 
            $r = 0; 
            for ( $j = 14; $j -ge 0; $j-- ) 
               $r = $r * 256;
               $r = $IntArr[ $j + 52 ] + $r;
               $IntArr[ $j + 52 ] =  [math]::Floor( [double]( $r / 24 ) ) 
               $r = $r % 24; 
            $PK = $TrTable[ $r ] + $PK;
         if ( $isWin8 -eq 1 )
            $t1 = $PK.Substring( 1, $r );
            $PK = $PK.Substring( 1 ).replace( $t1, $t1 + 'N' );
            if ( $r -eq 0 ) { $PK = 'N' + $PK };
         return "" +`
                $PK.Substring(  0, 5 ) + "-" +`
                $PK.Substring(  5, 5 ) + "-" +`
                $PK.Substring( 10, 5 ) + "-" +`
                $PK.Substring( 15, 5 ) + "-" +` 
                $PK.Substring( 20, 5 );
    • Worked for server 2016
  • return same value
    6 Posts | Last post April 26, 2017
    • Two questions. 
      Is there a new version of this script? 
      If no the script returns the same value on any device I run it on. I tested it on a windows 7 sp1 machine, a windows server 2012 datacenter and a windows server 2008 r2 standard and got the same product key on all machines when i ran the script.
    • I have mashed together this script, and another for this working current example:
    • I am retrieving keys for Windows Server 2012 and I have product keys I used - just not sure which system is using which key - but the script is returning keys that are none of the ones I used - so don't think this script is working for Server 2012 - thoughts?  OSVersion is returning 6.2.9200.
    • Are you using the updated version I posted in that github gist? That one works for me on 2012 R2.
    • Hi
      With the script on Githib, the product key retrieved is 
      for every server I tried (Windows Server 2012 R2 from a Windows Server 2012 R2)
    • Claude Renglet:
      I got the same error on a Windows Server 2012R2. I disconnect from my user and connect with the administrator account. Launch the powershell interface and do the command again. 
      That fix my problem and I got the product key.
      Hope that solution work for you !
      Thank you !
  • Wrong license key
    4 Posts | Last post March 01, 2017
    • When I put the Get-ProductKey -Computername command in, it tells me what version of windows and all. The only problem is it is giving me the wrong license key for the computer I am looking up. It gives the exact same license key every time. How do I fix this issue?
    • I'm having same problem. Scripts gives you wrong key number :)
    • I was getting the same product key returned on windows server 2012 standard x64 and windows 7 pro x64.
      If however you edit the script and change DigitalProductId4 to DigitalProductId I now receive back the correct key for windows 7 pro x64 as is on the COA sticker. I cannot confirm whether the windows server 2012 standard x64 is correct as I do not have the COA to check against, although I do get a different key.
      If this works for you, please confirm for others whether this returns the correct key against the COA and what version of OS you have.
    • Thank you, Peter!  Your suggestion also worked for me, as I am now collecting the correct product keys.
  • Result on Windows 8.1
    2 Posts | Last post March 01, 2017
    • It gets my OSDescription and OSVersion, but ProductKey is "Exception calling...". I have PowerShell 4.0 installed and running as admin.
    • I was experiencing the same issue.  Ensure that the Remote Registry service is running on the target machine before running this script.
  • Doesn't work
    7 Posts | Last post February 11, 2017
    • Run on different computers the script retrieves the same product key
    • More information would be helpful. What OS are you running it on and what OS's are you running it against?
    • I'm using Win 7 pro, run against Win7 pro, XP pro. All PCs have oem OS.
    • What kind of error messages are you seeing for this?
    • No errors, simply same product code for different computers
    • Not working on Windows 8 computers
  • Script does nothing
    3 Posts | Last post September 02, 2016
    • script does not work. nothing happens! HELP! For people like me that know zilch about programming, can anyone here tell me how to make this script work? I get nothing after running script. I opened up a powershell window with admin privileges. and typed everything in the quotes: "./Get-ProductKey.ps1 -Computername brb-rstirtz" and nothing happens. It just goes right back to the prompt at the command line. Can anyone help with this?
    • same as me! Tried to run on local host, it does not return anything!
    • Put on the script, on the end:
      Get-ProductKey -Computername $computer
      and run. Works for me!
  • Same key output for multiple machines
    1 Posts | Last post April 28, 2016
    • I have several Windows 10 Professional machines, each with a retail Windows 10 key (purchased separately from the PC). When I run the function (Get-ProductKey), all of the machines show the same value of for "ProductKey".
      Any thoughts on why that would be? I have verified that the last group of characters on each machine is different (through the Settings -> Update & Security -> Activation), so I know they are not using the same key.
  • Wrong key.
    1 Posts | Last post April 10, 2016
    • Hi Sir,
      Is there any solution on the output of keys?
      Meening - the "Partial Product Key" that "slmgr.vbs /dvl" retunes is nothing alike the one that your "Get-ProductKey.ps1" script retunes on a Activated Windows 2012 R2 DataCenter Edition.
  • Some license types will not show
    1 Posts | Last post March 31, 2016
    • Vista, Windows 7, 8, 10, Windows Server 2008, and 2012 operating systems using corporate MAK (Multiple Activation Keys) or VLK (Volume License Keys) cannot be recovered since they are not stored in the system. 
      Some key finder programs show the key as "BBBBB-BBBBB-BBBBB-BBBBB". Belarc is one popular example. 
  • Windows 8.1 failure
    2 Posts | Last post October 29, 2015
    • i run it on Windows 8.1 but for product key i have the "Exception calling "OpenRemoteBaseKey" .... anyway to fix this ?
    • I get the same error on Win7 pro x64 systems..
1 - 10 of 28 Items