Advertisement
Guest User

Powershell script using WMI to get Windows Product Key etc.

a guest
May 22nd, 2012
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.73 KB | None | 0 0
  1. function Calculate-ProductKey {
  2. param ($rpk)
  3.  
  4.     if ($rpk)#if rpk present - do math
  5.     {
  6.     $i = 28
  7.     $rpkOffset = 52
  8.     $PossibleChars = "BCDFGHJKMPQRTVWXY2346789"
  9.     do {
  10.         $Accumulator = 0
  11.         $j = 14
  12.         do {
  13.             $Accumulator = $Accumulator * 256
  14.             $Accumulator = $rpk[$j + $rpkOffset] + $Accumulator
  15.             $Accumulator / 24 -match "^\d*" | Out-Null
  16.             $rpk[$j + $rpkOffset] = $matches[0] -band 255
  17.             $Accumulator = $Accumulator % 24
  18.             $j--
  19.             } while ($j -ge 0)
  20.         $i--
  21.         $ProductKey = $PossibleChars.Substring($Accumulator, 1) + $ProductKey
  22.         if ((29 - $i) % 6 -eq 0 -and $i -ne -1) {
  23.             $i--
  24.             $ProductKey = "-" + $ProductKey
  25.         }
  26.     } while ($i -ge 0)
  27.     $ProductKey
  28.     }
  29.     else
  30.     { "Not Available" }
  31. }
  32.  
  33.  
  34. function Get-RegistryValues {
  35. param ($strcomputer)
  36.  
  37.     #create object for output
  38.     $object = new-object psobject
  39.     #create wmi object
  40.     $wmi2 = "\\"+$strComputer+"\root\default:stdRegProv"
  41.     $wmi = [wmiclass]$wmi2
  42.    
  43.     #get IE version
  44.     $hklm = 2147483650
  45.     $key = "SOFTWARE\Microsoft\Internet Explorer\"
  46.     $value = "Version"
  47.     $IEVersion = ($wmi.GetStringValue($hklm,$key,$value)).sValue
  48.    $object | add-member noteproperty IEVer ($IEVersion)
  49.    
  50.    #get windows product key
  51.    $key = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
  52.    $value = "DigitalProductId"
  53.    $WinPK = ($wmi.GetBinaryValue($hklm,$key,$value)).uValue
  54.    $WinPK = Calculate-ProductKey $WinPK
  55.    $object | add-member noteproperty WindowsProductKey ($WinPK)
  56.  
  57.    #get shell
  58.    $key = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\"
  59.    $value = "Shell"
  60.    $WindowsShell = ($wmi.GetStringValue($hklm,$key,$value)).sValue
  61.    $object | add-member noteproperty WindowsShell ($WindowsShell)
  62.    
  63.    #get userinit
  64.    $key = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\"
  65.    $value = "Userinit"
  66.    $UserInit = ($wmi.GetStringValue($hklm,$key,$value)).sValue
  67.    $object | add-member noteproperty UserInit ($UserInit)
  68.  
  69.    #get automatic updates status
  70.    $key = "SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU\"
  71.    $value = "NoAutoUpdate"
  72.    $NoAutoUpdate = ($wmi.GetDWORDValue($hklm,$key,$value)).uValue
  73.    $object | add-member noteproperty NoAutoUpdate ($NoAutoUpdate)
  74.    $value = "AUOptions"
  75.    $AUOptions = ($wmi.GetDWORDValue($hklm,$key,$value)).uValue
  76.    $object | add-member noteproperty AUOptions ($AUOptions)
  77.  
  78.    
  79.    #return object
  80.    $object
  81. }
  82.  
  83. # Usage:
  84. #
  85. # Get-RegistryValues [computername]
  86. # For ex.: Get-RegistryValues . (get values from local machine)
  87. # For ex.: Get-RegistryValues SUPERSERVER (get values from SUPERSERVER machine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement