PowerShell 技能连载 - 查找并提取注册表键的路径

适用于所有 PowerShell 版本

在前一个技巧中,我们演示了如何将一个 PowerShell 内部的路径格式转换为一个真实的路径。以下是一个用力。这段代码递归地搜索 HKEY_CURRENT_USER 键,并且找出所有包含单词“powershell”的注册表键(您可以将搜索关键字换成任何别的):

Get-ChildItem -Path HKCU:\ -Include *PowerShell* -Recurse -ErrorAction SilentlyContinue |
  Select-Object -Property *Path* |
  Out-GridView

这段代码输出所有名称中包含“Path”的属性。如您所见,注册表键中有两个属性包含该关键字:PSPathPSParentPath。两者都是 PowerShell 内置的路径格式。

要提取所有满足搜索条件的注册表键的路径,请使用以下代码:

Get-ChildItem -Path HKCU:\ -Include *PowerShell* -Recurse -ErrorAction SilentlyContinue |
  ForEach-Object {
    Convert-Path -Path $_.PSPath
  }

PowerShell 技能连载 - 查找并提取注册表键的路径

https://blog.vichamp.com/2014/07/31/finding-and-dumping-registry-key-paths/

作者

Victor Woo

发布于

2014-07-31

更新于

2014-07-31

许可协议

PowerShell 技术 QQ 群