getting the values of specific string values in registry keys with powershell

21,717

Solution 1

Get-ChildItem hkcu:\Test\Universe\Datawink\Switch1\Devices | ForEach-Object {Get-ItemProperty $_.pspath} | where-object {$_.Device} | Foreach-Object {$_.Device}

will give you the requested output.

(In your example the Where-Object is not really required)

Solution 2

This should work as well:

$path = 'hkcu:\Test\Universe\Datawink\Switch1\Devices'
Get-ChildItem $path | Get-ItemProperty | Select-Object -ExpandProperty Device
Share:
21,717
ar.dll
Author by

ar.dll

Updated on April 23, 2020

Comments

  • ar.dll
    ar.dll about 4 years

    Using the following powershell script:

    Get-ChildItem hkcu:\Test\Universe\Datawink\Switch1\Devices | ForEach-Object {Get-ItemProperty $_.pspath}
    

    I am able to get the following output:

    PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry1
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
    PSChildName  : Entry1
    PSProvider   : Microsoft.PowerShell.Core\Registry
    Device       : 2882881001
    Recordable   : Yes
    Active       : Yes
    
    PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry2
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
    PSChildName  : Entry2
    PSProvider   : Microsoft.PowerShell.Core\Registry
    Device       : 2882881002
    
    PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices\Entry3
    PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_CURRENT_USER\Test\Universe\Datawink\Switch1\Devices
    PSChildName  : Entry3
    PSProvider   : Microsoft.PowerShell.Core\Registry
    Device       : 2882881003
    

    Which is great, it's showing me the infomation I want, but all I really need is the values of the string entry called 'Device' so all I actually want is the output of the script to look like this:

    Device       : 2882881001
    Device       : 2882881002
    Device       : 2882881003
    

    or ideally, this:

    2882881001
    2882881002
    2882881003
    

    What's the simplest way to achieve this?