<# .PARAMETER DotNET_regPath Path in Registy .PARAMETER DotNET_regKey Name of Subkey in Registry .PARAMETER DotNET_releaseKey Release of the installed .NET Framework .PARAMETER log_File Output logged to that filename .PARAMETER Line_Break Breaks long lines in output .EXAMPLE Format: "528049" = ".NET Framework v4.8" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including other Windows 10 operating systems): 528049" "533325" = ".NET Framework v4.8.1" +$Line_Break+ "All other Windows operating systems: 533325" .LINK https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed #> # Path and Subkey in Registry $DotNET_regPath = "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" $DotNET_regKey = "Release" # .NET Framework version from Registry $DotNET_releaseKey = (Get-ItemProperty $DotNET_regPath -Name $DotNET_regKey).$DotNET_regKey # Log all information into that file $log_File = "C:\Temp\Get-.NET_Framework_Version" # Carriage Return $Line_Break = "`r`n" # valid .NET Framework releases $DotNET_Frameworks = @{ "378389" = ".NET Framework v4.5" +$Line_Break+ "All Windows operating systems: 378389" "378675" = ".NET Framework v4.5.1" +$Line_Break+ "On Windows 8.1 and Windows Server 2012 R2: 378675" "378758" = ".NET Framework v4.5.1" +$Line_Break+ "On all other Windows operating systems: 378758" "379893" = ".NET Framework v4.5.2" +$Line_Break+ "All Windows operating systems: 379893" "393295" = ".NET Framework v4.6" +$Line_Break+ "On Windows 10: 393295" "393297" = ".NET Framework v4.6" +$Line_Break+ "On all other Windows operating systems: 393297" "394254" = ".NET Framework v4.6.1" +$Line_Break+ "On Windows 10 November Update systems: 394254" "394271" = ".NET Framework v4.6.1" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including Windows 10): 394271" "394802" = ".NET Framework v4.6.2" +$Line_Break+ "On Windows 10 Anniversary Update and Windows Server 2016: 394802" "394806" = ".NET Framework v4.6.2" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including other Windows 10 operating systems): 394806" "460798" = ".NET Framework v4.7" +$Line_Break+ "On Windows 10 Creators Update: 460798" "460805" = ".NET Framework v4.7" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including other Windows 10 operating systems): 460805" "461308" = ".NET Framework v4.7.1" +$Line_Break+ "On Windows 10 Fall Creators Update" +$Line_Break+ "and Windows Server, version 1709: 461308" "461310" = ".NET Framework v4.7.1" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including other Windows 10 operating systems): 461310" "461808" = ".NET Framework v4.7.2" +$Line_Break+ "On Windows 10 April 2018 Update" +$Line_Break+ "and Windows Server, version 1803: 461808" "461814" = ".NET Framework v4.7.2" +$Line_Break+ "On all Windows operating systems" +$Line_Break+ "other than Windows 10 April 2018 Update" +$Line_Break+ "and Windows Server, version 1803: 461814" "528040" = ".NET Framework v4.8" +$Line_Break+ "On Windows 10 May 2019 Update" +$Line_Break+ "and Windows 10 November 2019 Update: 528040" "528372" = ".NET Framework v4.8" +$Line_Break+ "On Windows 10 May 2020 Update," +$Line_Break+ "October 2020 Update, May 2021 Update," +$Line_Break+ "November 2021 Update, and 2022 Update: 528372" "528449" = ".NET Framework v4.8" +$Line_Break+ "On Windows 11 and Windows Server 2022: 528449" "528049" = ".NET Framework v4.8" +$Line_Break+ "On all other Windows operating systems" +$Line_Break+ "(including other Windows 10 operating systems): 528049" "533320" = ".NET Framework v4.8.1" +$Line_Break+ "On Windows 11 2022 Update: 533320" "533325" = ".NET Framework v4.8.1" +$Line_Break+ "All other Windows operating systems: 533325" } # Function to generate Message in Log function log_Output { Param ( $output ) # Current date $date = (Get-Date -format "yyyy-MM-dd_HH-mm-ss") $ldate = (Get-Date -format "yyyy-MM-dd_HH-mm") # Skript Log $log_File = "{0}-{1}.log" -f $log_File, $ldate # Format a log message $message = "{0}: {1}" -f $date, $($output) $message = $message | Out-File $log_File -Append } # Only execute if Release is valid if ($DotNET_releaseKey) { # Iterate through list foreach ($DotNET_Key in $DotNET_Frameworks.Keys) { # Compare key with list of releases if ($DotNET_Key -eq $DotNET_releaseKey) { # Build a message string $message = "{0}" -f $DotNET_Frameworks[$DotNET_Key] # Log message to Stdout Write-Output $message # Log message to a protocol log_Output $message exit 0 } } # Build a message string $message = "Unable to detect a valid .NET Framework Version." # Log message to Stdout Write-Output $message # Log message to a protocol log_Output $message } exit 0