private/Step-BuildBootCoreWinPEStartupAssets.ps1

#Requires -PSEdition Core

function Step-BuildBootCoreWinPEStartupAssets {
    <#
    .SYNOPSIS
        Copies profile-local WinPEStartup assets into the mounted WinPE image
 
    .DESCRIPTION
        Clears the current session error collection, then recursively copies every
        top-level item from the build profile's WinPEStartup\assets directory into
        WinPEStartup\assets under the mounted image. The destination directory is
        created when needed, and existing destination content is overwritten.
 
        The function returns without changes when no build profile is set or the
        profile-local assets directory does not exist.
 
    .EXAMPLE
        PS> Step-BuildBootCoreWinPEStartupAssets
 
        Copies available profile-local startup assets into the mounted image.
 
    .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-28
 
        Requires global BuildMedia.BuildProfile and BuildMedia.MountPath.
        BuildProfileContentPath optionally overrides the profile-local content directory.
        Clears the automatic Error collection and modifies files under the mounted image.
    #>

    [CmdletBinding()]
    param ()

    $Error.Clear()

    $BuildProfilePath = $global:BuildMedia.BuildProfile
    $BuildProfileContentPath = $global:BuildMedia.BuildProfileContentPath
    if (-not $BuildProfileContentPath -and $BuildProfilePath) {
        $BuildProfileContentPath = Split-Path -Path $BuildProfilePath -Parent
    }
    if (-not $BuildProfileContentPath) { return }

    $SourceAssetsPath = Join-Path $BuildProfileContentPath 'WinPEStartup' 'assets'
    if (-not (Test-Path -LiteralPath $SourceAssetsPath -PathType Container)) { return }

    $DestinationAssetsPath = Join-Path $global:BuildMedia.MountPath 'WinPEStartup' 'assets'
    if (-not (Test-Path -LiteralPath $DestinationAssetsPath -PathType Container)) {
        New-Item -ItemType Directory -Path $DestinationAssetsPath -Force | Out-Null
    }

    foreach ($Item in @(Get-ChildItem -LiteralPath $SourceAssetsPath -Force -ErrorAction SilentlyContinue)) {
        Write-Host -ForegroundColor DarkGray "[$(Get-Date -Format s)] [INFO] Copying $($Item.FullName)"
        Copy-Item -LiteralPath $Item.FullName -Destination $DestinationAssetsPath -Recurse -Force
    }
}