Jump to content

How to Use Windows PowerShell to Modify or Remove a Registry Key Value

0
  chco's Photo
Posted Sep 04 2010 02:14 AM

If you want to modify or remove a property of a specific registry key, then the following excerpt from the new O'Reilly book Windows PowerShell Cookbook, Second Edition can be of service.

To set the value of a registry key, use the Set-ItemProperty cmdlet:

PS > (Get-ItemProperty .).MyProgram
c:\temp\MyProgram.exe
PS > Set-ItemProperty . MyProgram d:\Lee\tools\MyProgram.exe
PS > (Get-ItemProperty .).MyProgram
d:\Lee\tools\MyProgram.exe


To remove the value of a registry key, use the Remove-ItemProperty cmdlet:

PS > Remove-ItemProperty . MyProgram
PS > (Get-ItemProperty .).MyProgram


In the registry provider, PowerShell treats registry keys as items and key values as properties of those items. To change the value of a key property, use the Set-ItemProperty cmdlet. The Set-ItemProperty cmdlet has the standard alias sp. To remove a key property altogether, use the Remove-ItemProperty cmdlet.


Warning: As always, use caution when changing information in the registry. Deleting or changing the wrong item can easily render your system unbootable.



For more information about the Get-ItemProperty cmdlet, type Get-Help Get-ItemProperty. For information about the Set-ItemProperty and Remove-ItemProperty cmdlets, type Get-Help Set-ItemProperty or Get-Help Remove-ItemProperty, respectively. For more information about the registry provider, type Get-Help Registry.

Cover of Windows PowerShell Cookbook
Learn more about this topic from Windows PowerShell Cookbook, 2nd Edition. 

This introduction to the Windows PowerShell language and scripting environment provides more than 430 task-oriented recipes to help you solve the most complex and pressing problems, and includes more than 100 tried-and-tested scripts that intermediate to advanced system administrators can copy and use immediately. You'll find hands-on tutorials on fundamentals, common tasks, and administrative jobs that you can apply whether you're on a client or server version of Windows.

Learn More Read Now on Safari


Tags:
0 Subscribe


0 Replies