How to get registry value data value inside key using powershell

In my function, I would like to find a specific row in the data part of a particular subsection. Part of the internal function of the code:

 foreach ($CurrentPath in $Path) { 
    $Items = Get-Item -Path Registry::$CurrentPath
    ForEach ( $Property in $Items) {
      $Key = $Property

When I debug right after $Key = $Propertyand go to the host command window and type $Keyand press enter. He returns with:

Hive: hkcu

Name property
---- --------
ABC Test: ababab \ MSSQLSERVER_2014 \ ababab

I would like my function to also search in the data part, as shown in the attached image, which is in regedit.

Sample Image Regedit

How to perform a search?

+4
source share
1 answer

-, . Get-Item:

$item = Get-Item -Path "Registry::HKEY_CURRENT_USER\Software\NuGet"

foreach ($prop in $item.Property) {
    if($item.GetValue($prop) -match '0') { "Match found in key $($item.PSPath) , value $($prop)" }
}

Get-ItemProperty:

$item = Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Software\NuGet"

foreach ($prop in $item.psobject.Properties) {
    if($prop.Value -match '0') { "Match found in key $($item.PSPath) , value $($prop.Name)" }   
}

-, Get-ItemProperty Where-Object, ex:

Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Software\NuGet" | Where-Object { $_.IncludePrerelease -match '0' }
0

Source: https://habr.com/ru/post/1675182/


All Articles