private/Get-OSDeployOperatingSystemTarget.ps1

#Requires -PSEdition Core

function Get-OSDeployOperatingSystemTarget {
    <#
    .SYNOPSIS
        Gets the supported OSDeploy operating system target for this host
 
    .DESCRIPTION
        Requires Windows 11 25H2 build 26200 or Windows 11 26H2 build 26300. When
        RequireAdk is specified, the installed ADK must be exactly 10.1.26100.2454
        or 10.1.26100.9457 and the returned target is selected from the host build
        and ADK version.
 
    .PARAMETER RequireAdk
        Requires an installed ADK version supported for OS image workflows and
        includes its installation information in the result.
 
    .EXAMPLE
        PS> Get-OSDeployOperatingSystemTarget
 
        Returns the supported Windows release running on this host.
 
    .EXAMPLE
        PS> Get-OSDeployOperatingSystemTarget -RequireAdk
 
        Returns the Windows release target permitted by the host and installed ADK.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Management.Automation.PSCustomObject. Returns host and target build
        numbers, the target release folder, and ADK information when requested.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-10-05
    #>

    [CmdletBinding()]
    [OutputType([System.Management.Automation.PSCustomObject])]
    param (
        [Parameter()]
        [switch]
        $RequireAdk
    )

    $os = Get-CimInstance -ClassName Win32_OperatingSystem -ErrorAction Stop
    if ($null -eq $os -or $os.Caption -notlike '*Windows 11*') {
        throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Windows 11 25H2 or 26H2 is required."
    }

    [int]$hostBuildNumber = 0
    if (-not [int]::TryParse([string]$os.BuildNumber, [ref]$hostBuildNumber)) {
        throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Could not determine the Windows build number."
    }

    $hostRelease = switch ($hostBuildNumber) {
        26200 { 'Windows 11 25H2' }
        26300 { 'Windows 11 26H2' }
        default {
            throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Windows 11 25H2 (build 26200) or 26H2 (build 26300) is required. Detected build $hostBuildNumber."
        }
    }

    $targetBuildNumber = $hostBuildNumber
    $adkInfo = $null
    if ($RequireAdk) {
        $adkInfo = Get-OSDeployWindowsAdkInstall
        if (-not $adkInfo.IsInstalled) {
            throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Windows ADK 10.1.26100.2454 or 10.1.26100.9457 is required."
        }

        switch ([string]$adkInfo.InstallVersion) {
            '10.1.26100.2454' { $targetBuildNumber = 26200 }
            '10.1.26100.9457' {
                if ($hostBuildNumber -eq 26300) {
                    $targetBuildNumber = 26300
                }
                else {
                    $targetBuildNumber = 26200
                }
            }
            default {
                throw "[$(Get-Date -Format s)] [$($MyInvocation.MyCommand.Name)] Windows ADK $($adkInfo.InstallVersion) is not supported. Install ADK 10.1.26100.2454 or 10.1.26100.9457."
            }
        }
    }

    $targetRelease = switch ($targetBuildNumber) {
        26200 { 'Windows 11 25H2' }
        26300 { 'Windows 11 26H2' }
    }

    [pscustomobject]@{
        HostBuildNumber   = $hostBuildNumber
        HostRelease       = $hostRelease
        BuildMajor        = $targetBuildNumber
        OSFolderName      = $targetRelease
        AdkInfo           = $adkInfo
    }
}