private/BootMedia/Steps/Step-BootImageCustomWallpaper.ps1

#Requires -PSEdition Core

function Step-BootImageCustomWallpaper {
    <#
    .SYNOPSIS
        Copies a custom WinPE wallpaper from the winpe-wallpaper directory into the mounted image.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
 
        Looks for *.jpg files in $env:ProgramData\OSDeployCore\Repository\winpe-wallpaper.
        - 0 files found: continues silently.
        - 1 file found: copies it to $MountPath\Windows\System32\winpe.jpg.
        - 2+ files found: prompts via Out-GridView to select a single file, then copies it.
    #>

    [CmdletBinding()]
    param ()

    $MountPath           = $global:BuildMedia.MountPath
    $WinPECustomWallpaper = $global:BuildMedia.WinPECustomWallpaper

    if (-not $WinPECustomWallpaper) {
        return
    }

    if (-not (Test-Path -LiteralPath $WinPECustomWallpaper)) {
        Write-Warning "Custom wallpaper not found: $WinPECustomWallpaper"
        return
    }

    $Destination = "$MountPath\Windows\System32\winpe.jpg"
    Write-OSDeployCoreProgress "Copying custom wallpaper $WinPECustomWallpaper"

    if (Test-Path -LiteralPath $Destination) {
        # Take ownership so we can modify the file
        & takeown.exe /F $Destination /A | Out-Null
        # Grant full control to Administrators
        & icacls.exe $Destination /grant 'Administrators:F' | Out-Null
        # Clear read-only and system attributes
        Set-ItemProperty -LiteralPath $Destination -Name Attributes -Value 'Normal'
        Remove-Item -LiteralPath $Destination -Force -ErrorAction SilentlyContinue
    }

    Copy-Item -Path $WinPECustomWallpaper -Destination $Destination -Force
}