Created
March 28, 2017 20:38
-
-
Save radleta/b4c4b34b31dbe2b09421a7c3e4a9b4d9 to your computer and use it in GitHub Desktop.
PowerShell to Get the .NET Framework Versions Installed on a Remote Machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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 | |
Last Update : Aug-2016 | |
Keywords : NETFX, Registry | |
Reference : https://msdn.microsoft.com/en-us/library/hh925568 | |
#> | |
param($ComputerName = $env:COMPUTERNAME) | |
#param($ComputerName = 'remotemachinename') | |
#$ComputerName = Get-Content 'c:\servers.txt' | |
$dotNetRegistry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP' | |
$dotNet4Registry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | |
$dotNet4Builds = @{ | |
30319 = '.NET Framework 4.0' | |
378389 = '.NET Framework 4.5' | |
378675 = '.NET Framework 4.5.1 (8.1/2012R2)' | |
378758 = '.NET Framework 4.5.1 (8/7 SP1/Vista SP2)' | |
379893 = '.NET Framework 4.5.2' | |
380042 = '.NET Framework 4.5 and later with KB3168275 rollup' | |
393295 = '.NET Framework 4.6 (Windows 10)' | |
393297 = '.NET Framework 4.6 (NON Windows 10)' | |
394254 = '.NET Framework 4.6.1 (Windows 10)' | |
394271 = '.NET Framework 4.6.1 (NON Windows 10)' | |
394802 = '.NET Framework 4.6.2 (Windows 10 Anniversary Update)' | |
394806 = '.NET Framework 4.6.2 (NON Windows 10)' | |
} | |
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 = [version]($versionKey.GetValue('Version', '')) | |
New-Object -TypeName PSObject -Property @{ | |
ComputerName = $Computer | |
NetFXBuild = $version.Build | |
NetFXVersion = '.NET Framework ' + $version.Major + '.' + $version.Minor | |
} | Select-Object ComputerName, NetFXVersion, NetFXBuild | |
} | |
} | |
} | |
if ($net4RegKey = $regKey.OpenSubKey("$dotNet4Registry")) { | |
if(-not ($net4Release = $net4RegKey.GetValue('Release'))) { | |
$net4Release = 30319 | |
} | |
New-Object -TypeName PSObject -Property @{ | |
ComputerName = $Computer | |
NetFXBuild = $net4Release | |
NetFXVersion = $dotNet4Builds[$net4Release] | |
} | Select-Object ComputerName, NetFXVersion, NetFXBuild | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added later versions:
$ComputerName = Get-Content 'C:\scripts\serverlist.txt'
$dotNetRegistry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP'
$dotNet4Registry = 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
$dotNet4Builds = @{
30319 = '.NET Framework 4.0'
378389 = '.NET Framework 4.5'
378675 = '.NET Framework 4.5.1 (8.1/2012R2)'
378758 = '.NET Framework 4.5.1 (8/7 SP1/Vista SP2)'
379893 = '.NET Framework 4.5.2'
380042 = '.NET Framework 4.5 and later with KB3168275 rollup'
393295 = '.NET Framework 4.6 (Windows 10)'
393297 = '.NET Framework 4.6 (NON Windows 10)'
394254 = '.NET Framework 4.6.1 (Windows 10)'
394271 = '.NET Framework 4.6.1 (NON Windows 10)'
394802 = '.NET Framework 4.6.2 (Windows 10 Anniversary Update)'
394806 = '.NET Framework 4.6.2 (NON Windows 10)'
460798 = '.NET Framework 4.7'
460805 = '.NET Framework 4.7'
61308 = '.NET Framework 4.7.1'
461310 = '.NET Framework 4.7.1'
461808 = '.NET Framework 4.7.2'
461814 = '.NET Framework 4.7.2'
528040 = '.NET Framework 4.8'
528049 = '.NET Framework 4.8'
}
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 = version)
New-Object -TypeName PSObject -Property @{
ComputerName = $Computer
NetFXBuild = $version.Build
NetFXVersion = '.NET Framework ' + $version.Major + '.' + $version.Minor
} | Select-Object ComputerName, NetFXVersion, NetFXBuild
}
}
}
if ($net4RegKey = $regKey.OpenSubKey("$dotNet4Registry")) {
if(-not ($net4Release = $net4RegKey.GetValue('Release'))) {
$net4Release = 30319
}
New-Object -TypeName PSObject -Property @{
ComputerName = $Computer
NetFXBuild = $net4Release
NetFXVersion = $dotNet4Builds[$net4Release]
} | Select-Object ComputerName, NetFXVersion, NetFXBuild
}
}
}