Skip to content

Instantly share code, notes, and snippets.

@juneb
Last active August 23, 2016 23:23
Show Gist options
  • Save juneb/3c65f486e2e8ceaaae7dc4f68e5d6609 to your computer and use it in GitHub Desktop.
Save juneb/3c65f486e2e8ceaaae7dc4f68e5d6609 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Gets the installed .NET versions.
.DESCRIPTION
Gets the versions of all installed Microsoft .NET Framework builds
installed on the local computer.
.EXAMPLE
.\Get-DotNetVersion
v2.0.50727
v3.0
v3.5
v4.0
4.6.1
.EXAMPLE
.\Get-DotNetVersion -Verbose
VERBOSE: 4.5+ release is 394254.
v2.0.50727
v3.0
v3.5
v4.0
4.6.2 or later
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.99
Created on: 2/8/2016 3:41 PM
Updated on: 8/23/2016
Created by: June Blender
Organization: SAPIEN Technologies, Inc
Filename: Get-DotNetVersion.ps1
===========================================================================
#>
[CmdletBinding()]
param ()
if (!($NDP = Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -ErrorAction SilentlyContinue))
{
throw "Can't find or access the NDP registry key (HKLM\Software\Microsoft\NET Framework Setup\NDP)"
}
$result = ($NDP | Where-Object PSChildName -Like "v*.*").PSChildName
if ($NDP.PSChildName -contains 'v4')
{
if ($release = (Get-ItemProperty -Name Release -Path 'hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\').release)
{
Write-Verbose -Message "4.5+ release is $release."
switch ($release)
{
{ $_ -ge 394802 } { $result += "4.6.2 or later"; break }
{ $_ -ge 394254 } { $result += "4.6.1"; break }
{ $_ -ge 393295 } { $result += "4.6"; break }
{ $_ -ge 379893 } { $result += "4.5.2"; break }
{ $_ -ge 378675 } { $result += "4.5.1"; break; }
{ $_ -ge 378389 } { $result += "4.5" ; break;}
default { Write-Information -MessageData "INFORMATION: No 4.5 or later version detected" -InformationAction Continue }
}
}
}
return $result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment