PowerShell: Getting Windows Product Key

Ever wanted to read out the Windows license key? In the Windows Registry, this key is present, but it is stored as a digital ID. To convert it back to the license key used to originally license the product, try this function. It uses some serious math:

function Get-ProductKey {   
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").digitalproductid[0x34..0x42] 
    $ProductKey = "" 
    for ($i = 24; $i -ge 0; $i--) {
      $r = 0
      for ($j = 14; $j -ge 0; $j--) {
        $r = ($r * 256) -bxor $value[$j]
        $value[$j] = [math]::Floor([double]($r/24))
        $r = $r % 24
      $ProductKey = $map[$r] + $ProductKey
      if (($i % 5) -eq 0 -and $i -ne 0) {
        $ProductKey = "-" + $ProductKey

2 thoughts on “PowerShell: Getting Windows Product Key

  1. I simply want to say I am beginner to blogs and seriously loved you’re web-site. Likely I’m likely to bookmark your site . You amazingly have great well written articles. Appreciate it for sharing with us your webpage.

Leave a Reply

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