Skip to content

Instantly share code, notes, and snippets.

@liger1978
Created April 15, 2025 10:34
Show Gist options
  • Save liger1978/343cf9e644004cb3dfa196b57d6396e2 to your computer and use it in GitHub Desktop.
Save liger1978/343cf9e644004cb3dfa196b57d6396e2 to your computer and use it in GitHub Desktop.
Get-ItemProperty 'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, Publisher | Out-String -Width 2000 | Out-File C:\InstalledSoftware_32bit.txt
Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' | Select-Object DisplayName, DisplayVersion, Publisher | Out-String -Width 2000 | Out-File C:\InstalledSoftware_64bit.txt
Function Get-WindowsKey {
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$digitalID = (Get-ItemProperty -Path $regPath).DigitalProductId
$productName = (Get-ItemProperty -Path $regPath).ProductName
$productID = (Get-ItemProperty -Path $regPath).ProductID
# Helper function to decode the binary data
Function ConvertTo-ProductKey($keyData) {
$chars = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"
# Detect Windows 8+ key
$isWin8 = ($keyData[66] / 6) -band 1
$keyData[66] = ($keyData[66] -band 0xF7) -bor (($isWin8 -band 2) * 4)
$decodedKey = ""
For ($i = 24; $i -ge 0; $i--) {
$current = 0
For ($j = 14; $j -ge 0; $j--) {
$current = ($current * 256) + $keyData[$j]
$keyData[$j] = [math]::Floor($current / 24)
$current = $current % 24
}
$decodedKey = $chars[$current] + $decodedKey
}
# For Windows 8+ retail keys, insert an extra 'N' after the first character
$part1 = $decodedKey.Substring(0,1)
if ($isWin8 -eq 1) {
$decodedKey = $part1 + "N" + $decodedKey.Substring(1)
}
return $decodedKey
}
# Decode and return as a custom object
$decoded = ConvertTo-ProductKey $digitalID
[PSCustomObject]@{
ProductName = $productName
ProductID = $productID
ProductKey = $decoded
}
}
# Retrieve and write to file
Get-WindowsKey | Out-File "C:\WinKey.txt"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment