Friday, 9 September 2011

New-WmiRegistryKey.ps1


  1. <# 
  2. .SYNOPSIS 
  3.     This script creates a new registry key using WMI. 
  4. .DESCRIPTION 
  5.     This script uses WMI to get create a new registry key. 
  6.     This is a re-write of a VB Sample Script 
  7. .NOTES 
  8.     File Name  : New-RegistryKey.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINK 
  12.     This script posted to: 
  13.         http://www.pshscripts.blogspot.com 
  14.     MSDN sample posted to: 
  15.         http://msdn.microsoft.com/en-us/library/aa394600%28VS.85%29.aspx 
  16. .EXAMPLE 
  17.     Psh[C:\foo]>New-WMIRegistryKey.ps1 
  18.     Key created 
  19. #> 
  20.  
  21. # Define Constants 
  22. $HKEY_Local_Machine =2147483650  
  23. $computer ='.' 
  24.  
  25. # Get Class to call static methods on 
  26. $reg = [WMIClass]"ROOT\DEFAULT:StdRegProv" 
  27.  
  28. # Define key to create 
  29. $Key     = "SOFTWARE\NewKey" 
  30.  
  31. # Create key and display reslts 
  32. $results   = $reg.CreateKey($HKEY_LOCAL_MACHINE, $Key
  33. If ($results.Returnvalue -eq 0) {"Key created"}  

No comments: