gpt4 book ai didi

powershell - 使用powershell获取注册表项中特定字符串值的值

转载 作者:行者123 更新时间:2023-12-02 18:46:48 25 4
gpt4 key购买 nike

使用以下 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

实现这一目标的最简单方法是什么?

最佳答案

这应该也有效:

$path = 'hkcu:\Test\Universe\Datawink\Switch1\Devices'
Get-ChildItem $path | Get-ItemProperty | Select-Object -ExpandProperty Device

关于powershell - 使用powershell获取注册表项中特定字符串值的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8150271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com