[CmdletBinding()]
param()

$ErrorActionPreference = 'Stop'
# Release-controlled setting. Update this value and redistribute the MAR package when the compliance build changes.
$minimumWindowsBuild = 26200

try
{
    $operatingSystem = Get-CimInstance -ClassName Win32_OperatingSystem
    $currentBuild = 0
    if(-not [int]::TryParse([string]$operatingSystem.BuildNumber, [ref]$currentBuild))
    {
        throw "Windows reported an invalid OS build number: $($operatingSystem.BuildNumber)"
    }

    Write-Host "Detected OS: $($operatingSystem.Caption) (build $currentBuild)"
    Write-Host "Required minimum Windows build: $minimumWindowsBuild"
    if($currentBuild -lt $minimumWindowsBuild)
    {
        Write-Host "Windows build $currentBuild is below the required build $minimumWindowsBuild. Update Windows before running MAR provisioning." -ForegroundColor Red
        exit 1
    }

    Write-Host 'Windows build requirement met.' -ForegroundColor Green
    exit 0
}
catch
{
    Write-Host "Unable to validate the Windows build: $($_.Exception.Message)" -ForegroundColor Red
    exit 1
}
