private/Get-OSDeployWindowsAdkPaths.ps1

#Requires -PSEdition Core

function Get-OSDeployWindowsAdkPaths {
    <#
    .SYNOPSIS
        Resolves Windows ADK paths for an architecture
 
    .DESCRIPTION
        Builds the expected deployment tool, User State Migration Tool, Windows Setup,
        Windows PE, optional component, boot file, and executable paths beneath an existing
        Assessment and Deployment Kit root. The function prefers the language-specific
        en-us\winpe.wim path and falls back to the architecture root path without verifying
        that individual returned tool paths exist. A missing ADK root produces a warning
        and no object.
 
    .PARAMETER Architecture
        Specifies amd64 or arm64 for architecture-specific path construction.
 
    .PARAMETER AdkRoot
        Specifies the Assessment and Deployment Kit root directory. The path must exist.
 
    .EXAMPLE
        PS> Get-OSDeployWindowsAdkPaths -Architecture 'amd64' -AdkRoot 'C:\Program Files (x86)\Windows Kits\10\Assessment and Deployment Kit'
 
        Returns the expected amd64 Windows ADK tool and Windows PE paths beneath the given
        root.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Management.Automation.PSCustomObject. Returns one object containing AdkRoot,
        deployment directory paths, Windows PE paths, and named ADK executable and boot-file
        paths, or no object when AdkRoot does not exist.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 0.1.0
        Date: 2026-08-28
 
        Dependencies:
          Windows Features: Windows ADK and Windows ADK WinPE Addon path layout
          DotNet Classes: System.Management.Automation.PSCustomObject
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [ValidateSet('amd64', 'arm64')]
        [System.String]
        $Architecture,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [System.String]
        $AdkRoot
    )

    if (-not (Test-Path -Path $AdkRoot)) {
        Write-Warning "[$(Get-Date -Format s)] ADK root path not found: $AdkRoot"
        return $null
    }

    $deployTools = Join-Path $AdkRoot "Deployment Tools\$Architecture"
    $winpeRoot   = Join-Path $AdkRoot 'Windows Preinstallation Environment'
    $winpeArch   = Join-Path $winpeRoot $Architecture

    # Determine the WinPE source WIM path
    $wimSourcePath = Join-Path $winpeArch 'en-us\winpe.wim'
    if (-not (Test-Path $wimSourcePath)) {
        # Try without language subdirectory
        $wimSourcePath = Join-Path $winpeArch 'winpe.wim'
    }

    $result = [ordered]@{
        AdkRoot             = $AdkRoot
        PathBCDBoot         = Join-Path $deployTools 'BCDBoot'
        PathDeploymentTools = $deployTools
        PathDISM            = Join-Path $deployTools 'DISM'
        PathOscdimg         = Join-Path $deployTools 'Oscdimg'
        PathUsmt            = Join-Path $AdkRoot "User State Migration Tool\$Architecture"
        PathWinPE           = $winpeArch
        PathWinPEMedia      = Join-Path $winpeArch 'Media'
        PathWinSetup        = Join-Path $AdkRoot "Windows Setup\$Architecture"
        WinPEOCs            = Join-Path $winpeArch 'WinPE_OCs'
        WinPERoot           = $winpeRoot
        WimSourcePath       = $wimSourcePath
        bcdbootexe          = Join-Path $deployTools 'BCDBoot\bcdboot.exe'
        bcdeditexe          = Join-Path $deployTools 'BCDBoot\bcdedit.exe'
        bootsectexe         = Join-Path $deployTools 'BCDBoot\bootsect.exe'
        dismexe             = Join-Path $deployTools 'DISM\dism.exe'
        efisysbin           = Join-Path $deployTools 'Oscdimg\efisys.bin'
        efisysnopromptbin   = Join-Path $deployTools 'Oscdimg\efisys_noprompt.bin'
        etfsbootcom         = Join-Path $deployTools 'Oscdimg\etfsboot.com'
        imagexexe           = Join-Path $deployTools 'DISM\imagex.exe'
        oa3toolexe          = Join-Path $deployTools 'Licensing\OA30\oa3tool.exe'
        oscdimgexe          = Join-Path $deployTools 'Oscdimg\oscdimg.exe'
        pkgmgrexe           = Join-Path $deployTools 'DISM\pkgmgr.exe'
    }

    [PSCustomObject]$result
}