private/BootMedia/Steps/Get-WindowsAdkInstallInfo.ps1

#Requires -PSEdition Core

function Get-WindowsAdkInstallInfo {
    <#
    .SYNOPSIS
        Detects the installed Windows ADK via the registry.
 
    .DESCRIPTION
        Reads the Windows Kits registry key to determine whether the Windows ADK is installed,
        and returns the install path and version if found.
 
    .OUTPUTS
        PSObject with properties: IsInstalled, InstallPath, InstallVersion
        Returns $null values when the ADK is not installed.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

    [CmdletBinding()]
    param ()

    $result = [ordered]@{
        IsInstalled    = $false
        InstallPath    = $null
        InstallVersion = $null
    }

    $regPath = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots'

    if (Test-Path -Path $regPath) {
        $kitsRoot = Get-ItemPropertyValue -Path $regPath -Name 'KitsRoot10' -ErrorAction SilentlyContinue
        if ($kitsRoot) {
            $adkPath = Join-Path $kitsRoot 'Assessment and Deployment Kit'
            if (Test-Path -Path $adkPath) {
                $result.IsInstalled = $true
                $result.InstallPath = $adkPath

                # Determine version from the WinPE OC directory names or registry
                $winpePath = Join-Path $adkPath 'Windows Preinstallation Environment'
                if (Test-Path $winpePath) {
                    # Try to get version from the winpe.wim file if available
                    $wimFile = Join-Path $winpePath 'amd64\en-us\winpe.wim'
                    if (-not (Test-Path $wimFile)) {
                        $wimFile = Join-Path $winpePath 'arm64\en-us\winpe.wim'
                    }
                    if (Test-Path $wimFile) {
                        try {
                            $wimInfo = Get-WindowsImage -ImagePath $wimFile -Index 1 -ErrorAction SilentlyContinue
                            if ($wimInfo) {
                                $result.InstallVersion = "$($wimInfo.MajorVersion).$($wimInfo.MinorVersion).$($wimInfo.Build).$($wimInfo.SPBuild)"
                            }
                        }
                        catch {
                            Write-Verbose "Could not read WinPE image version: $_"
                        }
                    }
                }

                # Fallback: use the KitsRoot10 path version segment
                if (-not $result.InstallVersion) {
                    $buildLabEx = Get-ItemPropertyValue -Path $regPath -Name 'BuildLabEx' -ErrorAction SilentlyContinue
                    if ($buildLabEx) {
                        $result.InstallVersion = $buildLabEx
                    }
                    else {
                        # Use the registry key names under Installed Roots as version indicators
                        $versionKeys = Get-ChildItem -Path $regPath -ErrorAction SilentlyContinue |
                            Select-Object -ExpandProperty PSChildName |
                            Sort-Object -Descending
                        if ($versionKeys) {
                            $result.InstallVersion = $versionKeys[0]
                        }
                    }
                }
            }
        }
    }

    [PSCustomObject]$result
}