Private/Test/Test-IsSupportedOS.ps1
|
function Test-IsSupportedOS { <# .SYNOPSIS Tests if the current Windows OS meets the minimum supported build requirement. .DESCRIPTION Checks if the Windows operating system build number is greater than 14393 (Windows Server 2016 / Windows 10 Anniversary Update version 1607). This function is Windows-only and uses WMI/CIM to query the OS build number. If the build number cannot be determined, returns $true with a warning to avoid blocking execution on systems where CIM queries may fail. .INPUTS None. This function does not accept pipeline input. .OUTPUTS System.Boolean Returns $true if the OS build is greater than 14393 or cannot be determined. Returns $false if the build is 14393 or lower. .EXAMPLE Test-IsSupportedOS Returns $true if running Windows Server 2016/Windows 10 1607 or later. .EXAMPLE if (-not (Test-IsSupportedOS)) { throw "This module requires Windows Server 2016 or Windows 10 Anniversary Update (1607) or later." } Throws an error if the OS does not meet minimum requirements. .NOTES This function is designed for Windows operating systems only. Minimum supported build: 14393 (Windows Server 2016 / Windows 10 version 1607) .LINK https://learn.microsoft.com/en-us/windows/release-health/release-information #> [CmdletBinding()] [OutputType([bool])] param ( ) #requires -Version 5.1 # Minimum supported build: Windows Server 2016 / Windows 10 Anniversary Update (1607) $MinSupportedBuild = 14393 try { $os = Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction Stop Write-Verbose "Operating System: $($os.Caption) (Build Number: $($os.BuildNumber))" ($os.BuildNumber -gt $MinSupportedBuild) } catch { Write-Warning "Unable to determine OS build number. Assuming supported OS. Error: $_" $true } } |