In this demo we will see how to clear registry keys and values without
deleting it using Clear‑Item and Clear‑ItemProperty command.
Next,
we will see how to completely delete registry keys and values
using Remove‑Item and Remove‑ItemProperty command.
In this demo we will see how to clear the registry keys and values.
First,
I'll show you how to clear a property value using Clear‑ItemProperty command.
Before that,
I'll run get ItemProperty command to check the value of
OldInstallPath property that resides under App2 registry key.
We can see that the value is set to C:\Temp.
Now, I'll run Clear‑ItemProperty command.
Here you will have to provide the path in the Path parameter.
I'll enter App2, as the property that we are clearing resides under this key.
In the Name parameter, I'll enter property name which
is, in our case, is OldInstallPath.
I'll hit Enter and execute the command. Again when I can Get‑ItemProperty
command, we can see that the value has been cleared.
Next, I will delete this property using Remove‑ItemProperty command.
This will not only remove the value but will completely delete the
property from the registry key. Since the command syntax is same,
I'll just replace Clear‑ItemProperty command with
Remove‑ItemProperty and execute the command.
Now when I run Get‑ItemProperty command we get an error stating
that OldInstallPath property does not exist.
That's because it was deleted in the previous step.
We will now see how we can clear and delete the registry key.
Clear‑ltem will not delete the registry key, but it
will just remove its content.
I'll first run Clear‑Item command.
I need to provide the complete path of the registry that I wish to clear.
Here I'll enter .\App2\ and hit Enter.
When I switch to registry console and do a refresh, we can see
that all the contents of App2 registry key are cleared, and
only the default entry remains.
I will now show you how we can delete the registry key.
We will delete the App2 registry key using Remove‑Item command. In
the Path parameter I'll enter App2. You can also add Confirm
parameter while deleting the registry key.
This will prompt you to confirm before deleting.
As of now, I'll remove the Confirm parameter and proceed with deleting the key.
As soon as I had to Enter, the registry key gets deleted.
When we switch to registry console and do a refresh, we can see that the App2 key, along with its properties, is now deleted.