2011-11-16 21 views
2

とレジストリキー内の特定の文字列値の値を取得:次のPowerShellスクリプトを使用してPowerShellを

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

私は次のような出力を得ることができています:

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 

素晴らしいですが、それは見せて私には必要な情報がありますが、本当に必要なのは、 'Device'という文字列エントリの値です。実際には、このようなスクリプトの出力が必要です。

Device  : 2882881001 
Device  : 2882881002 
Device  : 2882881003 

または理想的には、この:

2882881001 
2882881002 
2882881003 

これを達成する最も簡単な方法は何ですか?

答えて

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

の出力が表示されます。

5

これは、同様に動作するはずです(あなたの例ではどこ-オブジェクトが本当に必要とされていません):

$path = 'hkcu:\Test\Universe\Datawink\Switch1\Devices' 
Get-ChildItem $path | Get-ItemProperty | Select-Object -ExpandProperty Device 
関連する問題