Last active
December 21, 2017 23:45
-
-
Save vScripter/c47e0a7b13216c25ae49 to your computer and use it in GitHub Desktop.
Return windows product key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-WinProductKey { | |
$map="BCDFGHJKMPQRTVWXY2346789" | |
$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 | |
} | |
} | |
$ProductKey | |
} | |
# http://powershell.com/cs/blogs/tips/archive/2012/04/30/getting-windows-product-key.aspx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment