-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-NetFrameworkVersion.ps1
79 lines (76 loc) · 4.62 KB
/
Get-NetFrameworkVersion.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<#
Script Name : Get-NetFrameworkVersion.ps1
Description : This script reports the various .NET Framework versions installed on the local or a remote computer.
Author : Martin Schvartzman
Updated by : Andrew Price
Reference : https://msdn.microsoft.com/en-us/library/hh925568
#>
function Get-DotNetFrameworkVersion
{
param(
[string]$ComputerName = $env:COMPUTERNAME
)
$dotNetRegistry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP'
$dotNet4Registry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
$dotNet4Builds = @{
'30319' = @{ Version = [System.Version]'4.0' }
'378389' = @{ Version = [System.Version]'4.5' }
'378675' = @{ Version = [System.Version]'4.5.1' ; Comment = '(8.1/2012R2)' }
'378758' = @{ Version = [System.Version]'4.5.1' ; Comment = '(8/7 SP1/Vista SP2)' }
'379893' = @{ Version = [System.Version]'4.5.2' }
'380042' = @{ Version = [System.Version]'4.5' ; Comment = 'and later with KB3168275 rollup' }
'393295' = @{ Version = [System.Version]'4.6' ; Comment = '(Windows 10)' }
'393297' = @{ Version = [System.Version]'4.6' ; Comment = '(NON Windows 10)' }
'394254' = @{ Version = [System.Version]'4.6.1' ; Comment = '(Windows 10)' }
'394271' = @{ Version = [System.Version]'4.6.1' ; Comment = '(NON Windows 10)' }
'394802' = @{ Version = [System.Version]'4.6.2' ; Comment = '(Windows 10 Anniversary Update)' }
'394806' = @{ Version = [System.Version]'4.6.2' ; Comment = '(NON Windows 10)' }
'460798' = @{ Version = [System.Version]'4.7' ; Comment = '(Windows 10 Creators Update)' }
'460805' = @{ Version = [System.Version]'4.7' ; Comment = '(NON Windows 10)' }
'461308' = @{ Version = [System.Version]'4.7.1' ; Comment = '(Windows 10 Fall Creators Update)' }
'461310' = @{ Version = [System.Version]'4.7.1' ; Comment = '(NON Windows 10)' }
'461808' = @{ Version = [System.Version]'4.7.0356'; }
'528040' = @{ Version = [System.Version]'4.8' ; Comment = '(Windows 10 November 2019 Update)' }
'528372' = @{ Version = [System.Version]'4.8' ; Comment = '(Windows 10 October 2020 Update)' }
'528049' = @{ Version = [System.Version]'4.8' ; Comment = '(On all other Windows O S)'}
'528449' = @{ Version = [System.Version]'4.8' ; Comment = '(On Windows 11 and Windows Server 2022)' }
'533320' = @{ Version = [System.Version]'4.8.1' ; Comment = '(Windows 11 2022 Update)' }
'533325' = @{ Version = [System.Version]'4.8.1' ; Comment = '(All other Windows operating systems)' }
}
foreach($computer in $ComputerName)
{
if($regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer))
{
if ($netRegKey = $regKey.OpenSubKey("$dotNetRegistry"))
{
foreach ($versionKeyName in $netRegKey.GetSubKeyNames())
{
if ($versionKeyName -match '^v[123]') {
$versionKey = $netRegKey.OpenSubKey($versionKeyName)
$version = [System.Version]($versionKey.GetValue('Version', ''))
New-Object -TypeName PSObject -Property ([ordered]@{
ComputerName = $computer
Build = $version.Build
Version = $version
Comment = ''
})
}
}
}
if ($net4RegKey = $regKey.OpenSubKey("$dotNet4Registry"))
{
if(-not ($net4Release = $net4RegKey.GetValue('Release')))
{
$net4Release = 30319
}
New-Object -TypeName PSObject -Property ([ordered]@{
ComputerName = $Computer
Build = $net4Release
Version = $dotNet4Builds["$net4Release"].Version
Comment = $dotNet4Builds["$net4Release"].Comment
})
}
}
}
}
Get-DotNetFrameworkVersion