Created
October 25, 2018 12:33
-
-
Save tnibert/20e3e868e4e8390553422f85101ef2b7 to your computer and use it in GitHub Desktop.
Get Windows key powershell script
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
# not made by me, but useful | |
$dpid = Get-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "DigitalProductId" | |
# Get the range we are interested in | |
$id = $dpid.DigitalProductId[52..(52+14)] | |
# Character table | |
$chars = "BCDFGHJKMPQRTVWXY2346789" | |
# Variable for the final product key | |
$pkey = "" | |
# Calculate the product key | |
for ($i=0; $i -le 24; $i++) { | |
$c = 0 | |
for($j=14; $j -ge 0; $j--) { | |
$c = ($c -shl 8) -bxor $id[$j] | |
$id[$j] = [Math]::Floor($c / 24) -band 255 | |
$c = $c % 24 | |
} | |
$pkey = $chars[$c] + $pkey | |
} | |
# Insert some dashes | |
for($i = 4; $i -gt 0; $i--) { | |
$pkey = $pkey.Insert($i * 5, "-") | |
} | |
$pkey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment