Last active
October 20, 2017 16:03
-
-
Save RichieBzzzt/13d486f800354273e10a6e9270790177 to your computer and use it in GitHub Desktop.
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
Function Test-NetInstalled { | |
param( | |
[Parameter(Position = 1, mandatory = $false)] | |
[String] $DotNetVersion | |
) | |
[Int] $RegEditDotNet | Out-Null | |
[bool] $RequiredVersion = $true | |
$dWord = Get-ChildItem "hklm:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" | Get-ItemPropertyValue -Name Release | |
if ($DotNetVersion) { | |
switch ($DotNetVersion) { | |
"4.5" { $RegEditDotNet = 378389} | |
"4.5.1" { $RegEditDotNet = 378675} | |
"4.5.2" { $RegEditDotNet = 379893} | |
"4.6" { $RegEditDotNet = 393295} | |
"4.6.1" { $RegEditDotNet = 394254} | |
"4.6.2" { $RegEditDotNet = 394802} | |
"4.7" { $RegEditDotNet = 460798} | |
"4.7.1" { $RegEditDotNet = 461308} | |
default {$RegEditDotNet = 0} | |
} | |
if ($dWord -lt $RegEditDotNet -or $RegEditDotNet -eq 0 ) { | |
Write-Error "You must have .NET $DotNetVersion installed on this machine to continue!" | |
$RequiredVersion = $false | |
} | |
else { | |
Write-Host "At least $DotNetVersion is installed!" -ForegroundColor White -BackgroundColor Red | |
} | |
} | |
switch ($dWord) { | |
378389 { $DotNetVersion = "4.5" } | |
378675 { $DotNetVersion = "4.5.1"} | |
379893 { $DotNetVersion = "4.5.2" } | |
393295 { $DotNetVersion = "4.6" } | |
394254 { $DotNetVersion = "4.6.1" } | |
394802 { $DotNetVersion = "4.6.2" } | |
460798 { $DotNetVersion = "4.7" } | |
461308 { $DotNetVersion = "4.7.1" } | |
} | |
$DotNetInfo = @{ DotNetVersion = $DotNetVersion; DWORD = $dWord[0]; RequiredVersion = $RequiredVersion} | |
return $DotNetInfo | |
} | |
$huh = Test-NetInstalled | |
Write-Host ".NET Version is $($huh.DotNetVersion), DWORD Value is $($huh.DWORD) and Required Version is $($huh.RequiredVersion)" -ForegroundColor White -BackgroundColor DarkGreen | |
$huh2 = Test-NetInstalled -DotNetVersion "4.6.1" | |
Write-Host ".NET Version is $($huh2.DotNetVersion), DWORD Value is $($huh2.DWORD) and Required Version is $($huh2.RequiredVersion)" -ForegroundColor White -BackgroundColor DarkMagenta | |
$huh3 = Test-NetInstalled -DotNetVersion "5.6.1" -ErrorAction Stop | |
Write-Host ".NET Version is $($huh3.DotNetVersion), DWORD Value is $($huh3.DWORD) and Required Version is $($huh3.RequiredVersion)" -ForegroundColor White -BackgroundColor DarkCyan | |
$huh4 = Test-NetInstalled -DotNetVersion "5.6.1" -ErrorAction Stop | |
Write-Host ".NET Version is $($huh4.DotNetVersion), DWORD Value is $($huh4.DWORD) and Required Version is $($huh4.RequiredVersion)" -ForegroundColor White -BackgroundColor DarkCyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment