Get .NET Framework version installed on Windows using PowerShell

How to find out installed version of .NET Framework with PowerShell

Finding out installed .NET Framework version on the host Windows OS is not an everyday job, but when it comes to deployments of the .NET application it is needed to check if the host supports targeting .NET Framework version.

Starting from .NET Framework 4.5, Microsoft is storing .NET Framework version as a key in registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release

Regedit -ffx

Depending on the key value, you can determine the version f the .NET Framework installed

.NET Framework VersionRegistry key value
.NET Framework 4.5 378389
.NET Framework 4.5.1 378675
.NET Framework 4.5.2 379893
.NET Framework 4.6 393295
.NET Framework 4.6.1 394254
.NET Framework 4.6.2 394802
.NET Framework 4.7 460798
.NET Framework 4.7.1 461308

Following this enumeration, it is easy to write PowerShell script for reading and retrieving .NET Framework version based on the value of the registry key value entry

$netRegKey = Get-Childitem "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
$release = $netRegKey.GetValue("Release")
$releases =@(
    @{id="378389";value=".NET Framework 4.5"},
    @{id="378675";value=".NET Framework 4.5.1"}
    @{id="379893";value=".NET Framework 4.5.2"},
    @{id="393295";value=".NET Framework 4.6"},
    @{id="394254";value=".NET Framework 4.6.1"},
    @{id="394802";value=".NET Framework 4.6.2"},
    @{id="460798";value=".NET Framework 4.7"},
    @{id="461308";value=".NET Framework 4.7.1"}
)


foreach($framework in $releases)
{
    if($framework.id -eq $release){
        Write-Output $framework.value
    }
}
    

 

References

Disclaimer

Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.


About the author

DEJAN STOJANOVIC

Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform includion ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus

.NET

read more

JavaScript

read more

SQL/T-SQL

read more

Umbraco CMS

read more

Comments for this article