Monday 12 September 2011

Get-WmiRegistryBinaryValue.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script Gets and displays a registry 
  4.     binary value using WMI. 
  5. .DESCRIPTION 
  6.     This script uses WMI to get, then display 
  7.     a binary registry Value. 
  8.     This is a re-write of a VB Sample Script. 
  9. .NOTES 
  10.     File Name  : Set-WmiRegistryBinaryValue.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx 
  18. .EXAMPLE 
  19.     Psh[C:\foo]>Get-WmiRegistryBinaryValue.ps1 
  20.     54 
  21.     46 
  22.     4c 
  23. #> 
  24.  
  25. # Define Constants 
  26. $HKEY_Local_Machine =2147483650  
  27. $computer ='.' 
  28.  
  29. # Get Class to call static methods on 
  30. $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv" 
  31.  
  32. # Define key to create 
  33. $ValueName = "Example Binary Value" 
  34. $Values     = @(0x54, 0x46, 0x4C) 
  35. $Key       = "SOFTWARE\NewKey" 
  36.  
  37. # Create Value entry 
  38. $results   = $reg.GetBinaryValue($HKEY_LOCAL_MACHINE, $Key, $ValueName
  39. Foreach ($byte in $results.uvalue) {"{0}" -f $byte.tostring("x")} 

W

No comments: