locked
Rertrieve registry key information only for those with a particular value RRS feed

  • Question

  • Hi,

    I am looking to retrieve all registry key informations with a particular value. So in my case all Oracle client information with TNS_Admin.

    [Array]$Arr_OracleKey=@("HKLM:\SOFTWARE\Wow6432Node\ORACLE","HKLM:\SOFTWARE\ORACLE")
                
    ForEach ($regkeyOracle in $Arr_OracleKey) {
                   
             If (Test-Path -Path $regkeyOracle -ErrorAction 'Stop') {
                                    
                [psobject[]]$regKeyApplication = Get-ChildItem -Path $regkeyOracle -ErrorAction 'Stop' | ForEach-Object { Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction 'SilentlyContinue' | Where {$_.TNS_ADMIN -ne $null}} -ErrorAction SilentlyContinue
             }
    	
    }

    My problem:

    Under Oracle key, some subkey have TNS_ADMIN and some don't so the liner is failing because some don't have TNS_ADMIN.

    How may I resolve that function to filter for only those with TNS_ADMIN?

    Thanks,

    Friday, February 8, 2019 1:32 PM

Answers

  • You should start with learning the very basics of Powershell.
    $RegKeyList = @(
    'HKLM:\SOFTWARE\Wow6432Node\ORACLE',
    'HKLM:\SOFTWARE\ORACLE'
    )
    $ValueName = 'TNS_ADMIN'
                
    ForEach ($RegKey in $RegKeyList) {
        Get-ChildItem -Path $RegKey -ErrorAction SilentlyContinue -Recurse | 
            Where-Object { Get-ItemProperty -Path $_.PSPath -Name $ValueName -ErrorAction SilentlyContinue} |
                Select-Object -Property *
    }


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, February 8, 2019 3:57 PM
    • Marked as answer by FRacine Friday, February 8, 2019 5:33 PM
    Friday, February 8, 2019 3:56 PM

All replies

  • You should start with learning the very basics of Powershell.
    $RegKeyList = @(
    'HKLM:\SOFTWARE\Wow6432Node\ORACLE',
    'HKLM:\SOFTWARE\ORACLE'
    )
    $ValueName = 'TNS_ADMIN'
                
    ForEach ($RegKey in $RegKeyList) {
        Get-ChildItem -Path $RegKey -ErrorAction SilentlyContinue -Recurse | 
            Where-Object { Get-ItemProperty -Path $_.PSPath -Name $ValueName -ErrorAction SilentlyContinue} |
                Select-Object -Property *
    }


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''


    • Edited by BOfH-666 Friday, February 8, 2019 3:57 PM
    • Marked as answer by FRacine Friday, February 8, 2019 5:33 PM
    Friday, February 8, 2019 3:56 PM
  • This is a frequently asked question.  If only get-itemproperty worked a little differently, it would be very easy.  How about something like this.  You can also pipe this to set-itemproperty.

    function get-itemproperty2 {
      # get-childitem skips top level key, use get-item
      param([parameter(ValueFromPipeline)]$key)
      process { 
        $key.getvaluenames() | foreach {
          $value = $_
          [pscustomobject] @{
            Path = $Key -replace 'HKEY_CURRENT_USER',
    'HKCU:' -replace 'HKEY_LOCAL_MACHINE','HKLM:' Name = $Value Value = $Key.GetValue($Value) Type = $Key.GetValueKind($Value) } } } }
    ls -r hkcu:\key1 | get-itemproperty2 | where name -eq name Path Name Value Type ---- ---- ----- ---- HKCU:\key1\key2 name 1 DWord


    ls -r hkcu:\key1 | get-itemproperty2 | where name -eq name |
    set-itemproperty -value 0
    • Edited by JS2010 Monday, February 11, 2019 7:52 PM
    Saturday, February 9, 2019 4:23 PM