[英]how to get the data value of the registry value inside a key using powershell
在我的函数中,我想在特定子项的数据部分中搜索特定字符串。 函数内部的代码部分如下:
foreach ($CurrentPath in $Path) {
$Items = Get-Item -Path Registry::$CurrentPath
ForEach ( $Property in $Items) {
$Key = $Property
当我在$Key = $Property
之后直接调试并转到主机命令窗口并键入$Key
并按Enter时。 它返回:
Hive: hkcu Name Property ---- -------- ABC Test : ababab\MSSQLSERVER_2014\ababab
我希望我的功能也可以搜索数据部分,如regedit中所附的图像所示。
如何完成搜索?
如果您不知道值名称,则需要循环属性。 使用Get-Item
示例:
$item = Get-Item -Path "Registry::HKEY_CURRENT_USER\Software\NuGet"
foreach ($prop in $item.Property) {
if($item.GetValue($prop) -match '0') { "Match found in key $($item.PSPath) , value $($prop)" }
}
或Get-ItemProperty
:
$item = Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Software\NuGet"
foreach ($prop in $item.psobject.Properties) {
if($prop.Value -match '0') { "Match found in key $($item.PSPath) , value $($prop.Name)" }
}
如果您知道值名称,那么使用Get-ItemProperty
和Where-Object
更容易,例如:
Get-ItemProperty -Path "Registry::HKEY_CURRENT_USER\Software\NuGet" | Where-Object { $_.IncludePrerelease -match '0' }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.