Managing the Registry
PowerShell has the ability to treat the registry like a file system. With little effort you can connect to the registry and navigate it just as you would a directory.
You can use Get-ItemProperty to view registry keys. For example, if we want to see the keys in our current registry location, we would use an expression like this:
You can also create a variable for an item's properties. Here we get the registry keys for Parameters from our current location:
We defined $ipparams to hold the registry keys from HKLM\System\CurrentControlSet\Services\Tcpip\Parameters. Invoking the variable lists all the keys and their values. Alternatively, we can get a specific key and value by specifying a property name: We can set a registry value using Set-Itemproperty. Here we changed the Domain key under parameters that had no value to a value of TEST:
To properly use Set-Itemproperty, you should specify a path. In this example we used a "." to indicate the current location, the name of the key and its new value. Because accessing the registry in PowerShell is like accessing a file system, you can recurse through it, search for specific items, or do a massive search and replace.
You can use New-Item and New-Itemproperty to create new registry keys and properties. Let's change our location to HKEY_Current_User and look at the current items in the root:
We use Remove-Item to remove the subkey we created:
Standard Registry Rules Apply
Since PowerShell takes a new approach to managing the registry, take great care in modifying the registry. Be sure to test your registry editing skills with these new expressions and cmdlets on a test system before even thinking about touching a production server or desktop.