Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get registryKey name alone instead of full registry keypath?

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?

like image 409
Samselvaprabu Avatar asked Jul 13 '12 13:07

Samselvaprabu


People also ask

What PowerShell command will list only the contents of a registry key or subkey?

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.

How do I query a registry key in PowerShell?

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 .

How do I delete a registry key in PowerShell?

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.

How do I browse the registry in PowerShell?

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.


2 Answers

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 image 100
Shay Levy Avatar answered Sep 22 '22 05:09

Shay Levy


Like this?

 $ComponentName=$Components | select pschildname
like image 22
CB. Avatar answered Sep 20 '22 05:09

CB.