在PowerShell中,如何获取具有特定属性的所有注册表项?

age*_*ped 3 registry powershell get-childitem

我想获取计算机上安装的所有Visual Studio版本的安装目录(将文件复制到Xml/Schemas目录中)

最好的方法是从注册表中读取.在\HKLM\Software\Wow6432Node\Microsoft\Visual Studio,所有版本按版本号列出:10.0,11.0,12.0.但是,即使没有安装,仍然存在9.0和8.0和7.1.所以我不能只抓住它们.我需要的是过滤所有具有InstallDir属性的键.

我知道我必须结合Get-ChildItem和Get-ItemProperty,但我不知道如何.

如何根据我的要求编写Powershell命令?

Goy*_*uix 6

这将在没有属性的键上生成错误 - 但您可以放心地忽略它们.

cd HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio
$paths = dir | gp -Name InstallDir | select InstallDir
Run Code Online (Sandbox Code Playgroud)

查看我安装了工作室2010和2012的计算机上$ paths变量的输出:

InstallDir
----------
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\
Run Code Online (Sandbox Code Playgroud)

神奇的是,Get-ItemProperty(GP)将接受来自管道的默认参数,这样就可以从链中的输出Get-ChildItem(DIR)自动检查每个子键.的Select-Object(选择)cmdlet的只是消除了PS*属性,让您不仅仅是原始路径:

  • 大!我检查了我是否可以在一行中完成所有操作,而不是`cd`到键中运行它.我可以!谢谢 (2认同)