<# .PARAMETER Build_Number BuildNumber from the current OS .PARAMETER log_File Output logged to that filename .PARAMETER LineBreak Breaks long lines in output .EXAMPLE Format: "19045" = "Windows 10 Version 22H2 (OS build 19045)" "22000" = "Windows 11 Version 21H2 (OS build 22000)" .LINK https://learn.microsoft.com/en-us/windows/release-health/release-information https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information #> # BuildNumber $Build_Number = (Get-WmiObject Win32_OperatingSystem).BuildNumber # Log all information into that file $log_File = "C:\Temp\Get-Windows_DisplayVersion" # Carriage Return $Line_Break = "`r`n" # valid Windows OS Releases $valid_BuildNumbers = @{ "9200" = "Windows 8" +$Line_Break+ "and Windows Server 2012 (OS build 9200)" "9600" = "Windows 8.1" +$Line_Break+ "and Windows Server 2012 R2 (OS build 9600)" "10240" = "Windows 10 Version 1507 (RTM) (OS build 10240)" "10586" = "Windows 10 Version 1511 (OS build 10586) - End of servicing" "14393" = "Windows 10 Version 1607" +$Line_Break+ "and Windows Server 2016 (OS build 14393) - End of servicing" "15063" = "Windows 10 Version 1703 (OS build 15063) - End of servicing" "16299" = "Windows 10 Version 1709 (OS build 16299) - End of servicing" "17134" = "Windows 10 Version 1803 (OS build 17134) - End of servicing" "17763" = "Windows 10 Version 1809" +$Line_Break+ "and Windows Server 2019 (OS build 17763)" "18362" = "Windows 10 Version 1903 (OS build 18362) - End of servicing" "18363" = "Windows 10 Version 1909 (OS build 18363) - End of servicing" "19041" = "Windows 10 Version 2004 (OS build 19041) - End of servicing" "19042" = "Windows 10 Version 20H2 (OS build 19042) - End of servicing" "19043" = "Windows 10 Version 21H1 (OS build 19043) - End of servicing" "19044" = "Windows 10 Version 21H2 (OS build 19044)" "19045" = "Windows 10 Version 22H2 (OS build 19045)" "22000" = "Windows 11 Version 21H1 (OS build 22000)" "22621" = "Windows 11 Version 22H2 (OS build 22621)" "22631" = "Windows 11 Version 23H2 (OS build 22631)" "20348" = "Windows Server 2022, Datacenter, Standard (OS build 20348)" } # 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 BuildNumber is valid if ($Build_Number) { # Iterate through list foreach ($BuildNumber_Key in $valid_BuildNumbers.Keys) { # Compare key with list of releases if ($BuildNumber_Key -eq $Build_Number) { # Build a message string $message = "{0}" -f $valid_BuildNumbers[$BuildNumber_Key] # Log message to Stdout Write-Output $message # Log message to a protocol log_Output $message exit 0 } } # Build a message string $message = "No valid Windows Version detected" # Log message to Stdout Write-Output $message # Log message to a protocol log_Output $message } exit 0