Tuesday 13 September 2011

Remove-WmiRegistryKey.ps1

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

No comments: