I was trying to get all the sub registry keys from registry key
$Key="hklm:\SOFTWARE\Wow6432Node\MyCompany\MyProj"
$ComponentKeys=Get-ChildItem -path $Key
$ComponentName=$Components | Select-object Name
$ComponentName
It displays the result like below
Name
----
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\Service
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\UserInterface
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\DataSetView
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\Notification
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\Model
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\MyCompany\MyProj\Management
But I just would like to retrieve the subkey name not the full name.
I need result like below
Name
----
Service
UserInterface
DataSetView
Notification
Model
Management
How to get the key name alone?
Listing All Subkeys of a Registry Key PowerShell. Core\Registry , but this can be shortened to just Registry . Any of the following commands will list the contents directly under HKCU: . Get-ChildItem -Path Registry::HKEY_CURRENT_USER Get-ChildItem -Path Microsoft.
One of the easiest ways to find registry keys and values is using the Get-ChildItem cmdlet. This uses PowerShell to get a registry value and more by enumerating items in PowerShell drives. In this case, that PowerShell drive is the HKLM drive found by running Get-PSDrive .
To delete the registry key using PowerShell, we can use the Remove-Item command. Remove-Item command removes the registry key from the path specified. For example, we have the registry key name NodeSoftware stored at the path HKLM, under the Software key.
You can browse the registry tree the same way you navigate your drives. HKLM:\ and HKCU:\ are used to access a specific registry hive. Those, you can access the registry key and their parameters using the same PowerShell cmdlets that you use to manage files and folders.
You can get names only with the Name switch:
$Key="hklm:\SOFTWARE\Wow6432Node\MyCompany\MyProj"
Get-ChildItem $key -Name
If you already have paths in a variable, use the Split-Path
cmdlet:
$componentName | Split-Path -Leaf
Like this?
$ComponentName=$Components | select pschildname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With