我想使用PowerShell在特定配置单元中查找包含字符串的所有注册表项和值,这些字符串foo可能嵌入在更长的字符串中。查找密钥并不难:
Get-ChildItem -path hkcu:\ -recurse -ErrorAction SilentlyContinue | Where-Object {$_.Name -like "*foo*"}
Run Code Online (Sandbox Code Playgroud)
问题是,由于我不提前知道属性的名称,因此我不知道找到值的最佳方法。我尝试了这个:
Get-ChildItem -path hkcu:\ -recurse -erroraction silentlycontinue | get-itemproperty | where {$_.'(default)' -like "*foo*"}
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误:
get-itemproperty : Specified cast is not valid.
At line:1 char:69
+ ... u:\ -recurse -erroraction silentlycontinue | get-itemproperty | where ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-ItemProperty], InvalidCastException
+ FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetItemPropertyCommand
Run Code Online (Sandbox Code Playgroud)
即使我添加-ErrorAction SilentlyContinue到了get-itemproperty。
此外,这只能找到(default)键的值。
另外,是否可以在单个命令中搜索所有蜂箱?
powershell ×1