My first guess is something involving WMI. Does anybody know better?
Clarification: One-Liner to return only the latest version for each installation of .NET
My first guess is something involving WMI. Does anybody know better?
Clarification: One-Liner to return only the latest version for each installation of .NET
I'm not up on my PowerShell syntax, but I think you could just call System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVerison(). This will return the version as a string (something like v2.0.50727
, I think).
[environment]::Version
Gives you an instance of Version
for the CLR the current copy of PSH is using (as documented here).
Not pretty. Definitely not pretty:
ls $Env:windir\Microsoft.NET\Framework | ? { $_.PSIsContainer } | select -exp Name -l 1
This may or may not work. But as far as the latest version is concerned this should be pretty reliable, as there are essentially empty folders for old versions (1.0, 1.1) but not newer ones – those only appear once the appropriate framework is installed.
Still, I suspect there must be a better way.
There's no reliable way to do this for all platforms and architectures using a simple script. If you want to learn how to do it reliably, start here:
http://blogs.msdn.com/b/astebner/archive/2006/08/02/687233.aspx
-Oisin
gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' | sort pschildname -des | select -fi 1 -exp pschildname
If you're going to use the registry you have to recurse in order to get the full version for the 4.0 Framework. The earlier answers both return the root number on my system for .Net 3.0 (where the WCF and WPF numbers, which are nested under 3.0, are higher -- I can't explain that), and fail to return anything for 4.0 ...
This looks right to me (note that it outputs separate version numbers for WCF & WPF on 3.0, I don't know what that's about). It also outputs both Client and Full on 4.0 (if you have them both installed):
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty Version -EA 0 |
Where { $_.PSChildName -match '^(?!S)\p{L}'} |
Select PSChildName, Version