private/Step-BuildBootInstallWinPEAppDaRT.ps1

function Step-BuildBootInstallWinPEAppDaRT {
    <#
    .SYNOPSIS
        Caches and installs Microsoft DaRT in the mounted WinPE image
 
    .DESCRIPTION
        Copies the locally installed Microsoft DaRT tools CAB and Microsoft Deployment
        Toolkit DaRT configuration into the shared microsoft-dart cache when available.
        Unless the media name contains public, the function expands the cached tools into
        the mounted image and records Microsoft DaRT in global BuildMedia.InstalledApps.
 
        The cached DaRT configuration is copied to Windows\System32 in the mounted image.
        Missing source and cache files produce informational host messages.
 
    .PARAMETER AppName
        Specifies the application name recorded in global BuildMedia.InstalledApps. Default
        is Microsoft DaRT.
 
    .EXAMPLE
        PS> Step-BuildBootInstallWinPEAppDaRT
 
        Caches locally installed DaRT content and installs available content into WinPE.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        None.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-30
 
        Requires global BuildMedia with MediaName, MountPath, WinPEAppsPath, and InstalledApps
        properties. Cache population requires Microsoft DaRT 10 and Microsoft Deployment
        Toolkit to be installed locally. Modifies the shared cache, mounted image, and global
        InstalledApps collection. Microsoft DaRT tools are available only for AMD64 images.
    #>

    [CmdletBinding()]
    param (
        [System.String]
        $AppName = 'Microsoft DaRT'
    )

    $Architecture = $global:BuildMedia.Architecture
    $MediaName = $global:BuildMedia.MediaName
    $MountPath = $global:BuildMedia.MountPath
    $WinPEAppsPath = $global:BuildMedia.WinPEAppsPath
    $AppCache = Join-Path $WinPEAppsPath 'microsoft-dart'

    if ($Architecture -ne 'amd64') {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Not supported for $Architecture BootMedia"
        return
    }

    $MicrosoftDartCabSource = Join-Path $env:ProgramFiles 'Microsoft DaRT\v10\Toolsx64.cab'
    $MicrosoftDartCab = Join-Path $AppCache 'Toolsx64.cab'
    if ((Test-Path -LiteralPath $MicrosoftDartCabSource) -and -not (Test-Path -LiteralPath $MicrosoftDartCab)) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Adding cache content at $AppCache"
        if (-not (Test-Path -LiteralPath $AppCache)) {
            New-Item -Path $AppCache -ItemType Directory -Force | Out-Null
        }
        Copy-Item -LiteralPath $MicrosoftDartCabSource -Destination $MicrosoftDartCab -Force | Out-Null
    }

    if (Test-Path -LiteralPath $MicrosoftDartCab) {
        if ($MediaName -match 'public') {
            Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Not adding Microsoft DaRT for Public BootMedia"
        }
        else {
            Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Using cache content at $MicrosoftDartCab"
            expand.exe $MicrosoftDartCab -F:*.* $MountPath | Out-Null
            $global:BuildMedia.InstalledApps += $AppName
        }
    }
    else {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Install Microsoft Desktop Optimization Pack to add Microsoft DaRT to BootImage"
    }

    $MicrosoftDartConfigSource = Join-Path $env:ProgramFiles 'Microsoft Deployment Toolkit\Templates\DartConfig8.dat'
    $MicrosoftDartConfig = Join-Path $AppCache 'DartConfig.dat'
    if ((Test-Path -LiteralPath $MicrosoftDartConfigSource) -and -not (Test-Path -LiteralPath $MicrosoftDartConfig)) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT Config: Adding cache content at $AppCache"
        if (-not (Test-Path -LiteralPath $AppCache)) {
            New-Item -Path $AppCache -ItemType Directory -Force | Out-Null
        }
        Copy-Item -LiteralPath $MicrosoftDartConfigSource -Destination $MicrosoftDartConfig -Force | Out-Null
    }

    if (Test-Path -LiteralPath $MicrosoftDartConfig) {
        Copy-Item -LiteralPath $MicrosoftDartConfig -Destination (Join-Path $MountPath 'Windows\System32\DartConfig.dat') -Force | Out-Null
    }
    else {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -format s)] [INFO] Microsoft DaRT: Install Microsoft Deployment Toolkit to add Microsoft DaRT Config to BootImage"
    }
}