I want to get the installation directories of all Visual Studio versions installed on a machine (to copy a file into the Xml/Schemas directory)
The best way is to read from the registry. At \HKLM\Software\Wow6432Node\Microsoft\Visual Studio
, all the versions are listed by version number: 10.0, 11.0, 12.0. However, 9.0 and 8.0 and 7.1 are still there, even though those aren't installed. So I can't just grab them all. What I need is to filter on all keys that have the InstallDir property.
I know I have to combine Get-ChildItem and Get-ItemProperty but I'm not sure how.
How do I write the Powershell command for what I'm asking?
This will generate errors on the keys that don't have the property - but you can safely ignore those.
Looking at the output of the $paths variable on my computer where I have studio 2010 and 2012 installed:
The magic is that
Get-ItemProperty
(gp) will accept the default parameter from the pipeline so that you can chain the output fromGet-ChildItem
(dir) to automatically check each of the sub-keys. TheSelect-Object
(select) cmdlet simply eliminates the PS* properties and gives you just the raw path: