Saturday, 10 September 2011

Set-WmiMultiStringValue.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script sets a registry binary value 
  4.     using WMI. 
  5. .DESCRIPTION 
  6.     This script uses WMI to set a multistring 
  7.     registry Value. 
  8.     This is a re-write of a VB Sample Script. 
  9. .NOTES 
  10.     File Name  : Set-WmiRegistryMultiStringValue.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]>Set-MultiStringValue.ps1 
  20.     Value created 
  21. #> 
  22.  
  23. # Define Constants 
  24. $HKEY_Local_Machine =2147483650  
  25. $computer ='.' 
  26.  
  27. # Get Class to call static methods on 
  28. $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv" 
  29.  
  30. # Define key to create 
  31. $Key       = "SOFTWARE\NewKey" 
  32. $ValueName = "Example MultiString Value" 
  33. $Values     = @("Thomas", "Susan", "Rebecca"
  34. $Key       = "SOFTWARE\NewKey" 
  35.  
  36. # Create Value entry 
  37. $results   = $reg.SetMultiStringValue($HKEY_LOCAL_MACHINE, $Key, $ValueName, $Values
  38. If ($results.Returnvalue -eq 0) {"Value Set"}  

No comments: