As you might know, We use Get-PSDrive cmdlet to list all the powershell drives.
As you can see in the screenshot above, there are two drives with providerRegistry, First one is HKCU i.e.HKEY_CURRENT_USER and second is HKLM i.e. HKEY_LOCAL_MACHINE.
Now let’s work with HKCU, for that we need to set current work location to HKCU, as shown below:
Now, we can use dir or Get-ChildItem to see the contents of HKCU and we can change working location to any of underlying directories.
You can use tab key on your keyboard in order to auto complete the directory names while navigating.
Now, let’s say you might want to see what contents/settings/keys there are for mouse under control panel and you can do that as below:
Note: You can use dir instead of Get-ChildItem.
Now change your current work location to Mouse under control panel and try listing contents:
As you can see, nothing gets listed. Remember that in the registry you can navigate down the keys such as ‘Mouse’ but cannot change the properties from that particular work location. For changing the properties, you need to change your work location to one level up i.e. Control Panel in this particular case and use Set-ItemProperty cmdlet as shown below:
Here, we are setting value of MouseTrails property to 1. Remember that you are supposed to do the changes in the directory only if you have enough awareness of the effects of the changes you make. In general, be careful while making any changes to registry by any means, as it may provide major impact on your system.
You can add new item or key by using New-Item cmdlet in registry:
Note that, first we have created a new key called ‘Test’ and then next by using New-ItemProperty, we have added a new property for key ‘Test’ with name ‘Property’. We can verify newly added property by using Get-Item again:
Let’s set some value for the new property using Set-ItemProperty cmdlet:
As you can see, we have set value 3 for the property named ‘Property’.
We can remove the keys from registry by using Remove-Item cmdlet:
As you can see, we get an error when we try to get ‘Test’ key as it is removed using Remove-Item.