Skip to content

Instantly share code, notes, and snippets.

@vScripter
Last active December 21, 2017 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vScripter/c47e0a7b13216c25ae49 to your computer and use it in GitHub Desktop.
Save vScripter/c47e0a7b13216c25ae49 to your computer and use it in GitHub Desktop.
Return windows product key
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