Reputation: 787
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?
Upvotes: 2
Views: 22327
Reputation: 126902
This should work as well:
$path = 'hkcu:\Test\Universe\Datawink\Switch1\Devices'
Get-ChildItem $path | Get-ItemProperty | Select-Object -ExpandProperty Device
Upvotes: 5
Reputation: 16646
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)
Upvotes: 3