Guest User

Untitled

a guest
Oct 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. function Get-WindowsKey
  2. {
  3. ## function to retrieve the Windows Product Key from any PC
  4. ## by Jakob Bindslet (jakob@bindslet.dk)
  5. param ($targets = ".")
  6. $hklm = 2147483650
  7. $regPath = "SoftwareMicrosoftWindows NTCurrentVersion"
  8. $regValue = "DigitalProductId"
  9. Foreach ($target in $targets) {
  10. $productKey = $null
  11. $win32os = $null
  12. $wmi = [WMIClass]"\$targetrootdefault:stdRegProv"
  13. $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
  14. $binArray = ($data.uValue)[52..66]
  15. $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"
  16. ## decrypt base24 encoded binary data
  17. For ($i = 24; $i -ge 0; $i--) {
  18. $k = 0
  19. For ($j = 14; $j -ge 0; $j--) {
  20. $k = $k * 256 -bxor $binArray[$j]
  21. $binArray[$j] = [math]::truncate($k / 24)
  22. $k = $k % 24
  23. }
  24. $productKey = $charsArray[$k] + $productKey
  25. If (($i % 5 -eq 0) -and ($i -ne 0)) {
  26. $productKey = "-" + $productKey
  27. }
  28. }
  29. $win32os = Get-WmiObject Win32_OperatingSystem -computer $target
  30. $obj = New-Object Object
  31. $obj | Add-Member Noteproperty Computer -value $target
  32. $obj | Add-Member Noteproperty Caption -value $win32os.Caption
  33. $obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion
  34. $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
  35. $obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber
  36. $obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser
  37. $obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber
  38. $obj | Add-Member Noteproperty ProductKey -value $productkey
  39. $obj
  40. }
  41. }
Add Comment
Please, Sign In to add comment