This will generate errors on the keys that don't have the property - but you can safely ignore those.
cd HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio
$paths = dir | gp -Name InstallDir | select InstallDir
Looking at the output of the $paths variable on my computer where I have studio 2010 and 2012 installed:
InstallDir
----------
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\
The magic is that Get-ItemProperty
(gp) will accept the default parameter from the pipeline so that you can chain the output from Get-ChildItem
(dir) to automatically check each of the sub-keys. The Select-Object
(select) cmdlet simply eliminates the PS* properties and gives you just the raw path: