Created
April 19, 2018 15:06
-
-
Save gioxx/4641c7a79cf2d8a9fe81384533fab21e to your computer and use it in GitHub Desktop.
Recupera la Product Key di Office via PowerShell (testato su Windows 10 e Microsoft Office 2016 ProPlus), vedi https://wp.me/pdQ5q-9dx
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-MSOfficeProductKey { | |
param( | |
[string[]]$computerName = "." | |
) | |
$product = @() | |
$hklm = 2147483650 | |
$path = "SOFTWARE\Microsoft\Office" | |
foreach ($computer in $computerName) { | |
$wmi = [WMIClass]"\\$computer\root\default:stdRegProv" | |
$subkeys1 = $wmi.EnumKey($hklm,$path) | |
foreach ($subkey1 in $subkeys1.snames) { | |
$subkeys2 = $wmi.EnumKey($hklm,"$path\$subkey1") | |
foreach ($subkey2 in $subkeys2.snames) { | |
$subkeys3 = $wmi.EnumKey($hklm,"$path\$subkey1\$subkey2") | |
foreach ($subkey3 in $subkeys3.snames) { | |
$subkeys4 = $wmi.EnumValues($hklm,"$path\$subkey1\$subkey2\$subkey3") | |
foreach ($subkey4 in $subkeys4.snames) { | |
if ($subkey4 -eq "digitalproductid") { | |
$temp = "" | select ComputerName,ProductName,ProductKey | |
$temp.ComputerName = $computer | |
$productName = $wmi.GetStringValue($hklm,"$path\$subkey1\$subkey2\$subkey3","productname") | |
$temp.ProductName = $productName.sValue | |
$data = $wmi.GetBinaryValue($hklm,"$path\$subkey1\$subkey2\$subkey3","digitalproductid") | |
$valueData = ($data.uValue)[52..66] | |
# decrypt base24 encoded binary data | |
$productKey = "" | |
$chars = "BCDFGHJKMPQRTVWXY2346789" | |
for ($i = 24; $i -ge 0; $i--) { | |
$r = 0 | |
for ($j = 14; $j -ge 0; $j--) { | |
$r = ($r * 256) -bxor $valueData[$j] | |
$valueData[$j] = [math]::Truncate($r / 24) | |
$r = $r % 24 | |
} | |
$productKey = $chars[$r] + $productKey | |
if (($i % 5) -eq 0 -and $i -ne 0) { | |
$productKey = "-" + $productKey | |
} | |
} | |
$temp.ProductKey = $productKey | |
$product += $temp | |
} | |
} | |
} | |
} | |
} | |
} | |
$product | |
} | |
Get-MSOfficeProductKey |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment