daily pastebin goal
66%
SHARE
TWEET

WindowsProductKey

jessicakennedy1028 Sep 10th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Get-WindowsKey {
  2.     param ($targets = ".")
  3.     $hklm = 2147483650
  4.     $regPath = "Software\Microsoft\Windows NT\CurrentVersion"
  5.     $regValue = "DigitalProductId"
  6.     Foreach ($target in $targets) {
  7.         $productKey = $null
  8.         $win32os = $null
  9.         $wmi = [WMIClass]"\\$target\root\default:stdRegProv"
  10.         $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
  11.         $binArray = ($data.uValue)[52..66]
  12.         $charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"
  13.  
  14.         ## decrypt base24 encoded binary data
  15.         For ($i = 24; $i -ge 0; $i--) {
  16.             $k = 0
  17.             For ($j = 14; $j -ge 0; $j--) {
  18.                 $k = $k * 256 -bxor $binArray[$j]
  19.                 $binArray[$j] = [math]::truncate($k / 24)
  20.                 $k = $k % 24
  21.             }
  22.             $productKey = $charsArray[$k] + $productKey
  23.             If (($i % 5 -eq 0) -and ($i -ne 0)) {
  24.                 $productKey = "-" + $productKey
  25.             }
  26.         }
  27.  
  28.         $win32os = Get-WmiObject Win32_OperatingSystem -computer $target
  29.         $obj = New-Object Object
  30.         $obj | Add-Member Noteproperty Computer -value $target
  31.         $obj | Add-Member Noteproperty Caption -value $win32os.Caption
  32.         $obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion
  33.         $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
  34.         $obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber
  35.         $obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser
  36.         $obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber
  37.         $obj | Add-Member Noteproperty ProductKey -value $productkey
  38.         $obj
  39.     }
  40. }
  41.  
  42. Clear-Host
  43. Get-WindowsKey
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top