0

I am writing a powershell script and have come across a problem. I have a registry key which contains one single value. I have to extract the name of the value as opposed to the it's value. To be a bit more clear, let us consider the key containing the DWORD value [@10.105.1.1 = 64]. I want to be able to extract the name of the value, in this case 10.105.1.1. I have no use of the value, 64, that it is set to. Also note, that I am not creating the registry key and the name of the value will vary from computer to computer as it is more of a setting used by another system, and I am only trying to access the settings data.

2
  • whats the question? what have you tried? and what does the "enumerate all" in the title have to do with what you described in the body? Jul 3, 2012 at 4:51
  • What I meant was that there might be multiple such values each with an IP in the name of the value. I would like to get all the IPs or at the very least the topmost one. Jul 3, 2012 at 5:49

2 Answers 2

1

You can get all values under a specified registry key, filter by the data of the values and then get the name of the Value. In the following example I'm listing the values under the CurrentVersion key, filter the values based on the data (games) and getting the Value name (SM_GamesName). This example requires the PSRemoteRegistry module:

Import-Module PSRemoteRegistry
$key = 'SOFTWARE\Microsoft\Windows\CurrentVersion'

Get-RegValue -Hive LocalMachine -Key $key | 
Where-Object {$_.Data -eq 'games'} | 
Foreach-Object { $_.Value }

SM_GamesName
0

I've been looking into recursively returning all values with a script.

# get-reg.ps1

Param($key)

Get-Item $key | foreach-object {
  $path = $_.PSPath
  $_.Property | foreach-object {
    $name = $_
    $data = get-itemproperty -literalpath $path -name $name |
      select -expand $name
    [pscustomobject]@{value=$name; data=$data; key=$path}
  }
}

Get-ChildItem -Recurse $key | foreach-object { # won't process top key
  $path = $_.PSPath
  $_.Property | foreach-object {
    $name = $_
    # there is a key named "*" under hklm:\software\classes
    $data = get-itemproperty -literalpath $path -name $name | 
      select -expand $name
    [pscustomobject]@{value=$name; data=$data; key=$path}
  }
}

PS C:\Users\js2010> .\get-reg hkcu:\key1

value     data     key
-----     ----     ---
value1    data1    Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\key1
(default) hi       Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\key1
value2    data2    Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\key1\key2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.