In this demo,
we will create new registry key and properties using
New‑Item and New‑ItemProperty command.
We will then modify these registry keys and values.
We will see how to change the value of property using Set‑ItemProperty
command and how we can rename registry keys and values.
We will now see how we can create new registry key and values.
For this.
I'll use New‑Item command to create a new registry key.
Note that a registry is equivalent to a file or a folder that
acts as a container to hold properties.
So just like we use New‑Item command to create a file or a folder,
I'll use it to create a registry key.
Under HKLM:\Software I'll create App1 registry key.
I'll hit Enter, and we can see the message that shows registry details.
Now to create the property under this newly created registry key,
I can either navigate to App1 key or create the property from here itself.
For creating properties and their values,
we must make use of New‑ItemProperty command.
I'll enter the complete path, which is, in our case, .\SOFTWARE\App1.
We will have to give it a name.
For testing purpose, you can give any valid name.
I'll name this property as InstallPath.
I will then have to provide a value for this property,
hence, I'll enter C:\ProgramFiles\App1, and hit Enter.
This will create the registry property with its values.
It's not mandatory that you enter the value of a property,
as this value can also be set to null.
To test this,
I'll create another property named NewInstallPath and set it to null.
Now, I'll open the Registry Editor and do a refresh,
then navigate to SOFTWARE and then App1.
Here we can see App1 key, and the properties got created.
The InstallPath property shows the value that we set.
Also note that the NewInstallPath property that we set as null is showing blank.
This is how you can create a registry key and value using
New‑Item and New‑ItemProperty commands.
Next, we will see how we can modify existing registry keys and values.
To do so, we'll use the same key that we created a while ago.
First, I'll go into the SOFTWARE folder.
To change the name of the registry key, you must use Rename‑Item command.
In the Path parameter,
I will enter the name of the registry of which I want to change the name.
In the NewName parameter, I'll enter the NewName and hit Enter.
This will change the name of the registry key from App1 to App2.
To change the name of a property, I'll use Rename‑ItemProperty.
In the Path parameter, I'll enter the path, which has now
changed to App2. In the Name parameter, I'll enter the name of
the property that I wish to change.
I will change one of the properties that we created earlier.
I will change the name from NewInstallPath to OldInstallPath.
I'll enter a new name and NewName parameter and hit Enter.
Now when I go to registry snap‑in and do a refresh, you will notice that
the registry key name changed from App1 to App2, and property name changed
from NewInstallPath to OldInstallPath. Next, you can modify the registry
values using Set‑ItemProperty command.
We will set the value of OldInstallPath property from null to some value.
I'll enter Set‑ItemProperty command. In the Path parameter, I'll enter
App2. In the Name parameter, I'll mention the name of the property of
which I wish to change the value. Next, in the Value parameter, I'll
enter the value that I wish to set.
I'll enter C:\Temp and hit Enter.
Now, when we check the value from registry console, we can see that the value of the property has been modified.