private/BootMedia/Steps/Step-BootImageDriver.ps1

#Requires -PSEdition Core

function Step-BootImageDriver {
    <#
    .SYNOPSIS
        Adds selected WinPE drivers to the mounted image via Add-WindowsDriver.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

    [CmdletBinding()]
    param ()

    $MountPath = $global:BuildMedia.MountPath
    $WinPEDriver = $global:BuildMedia.WinPEDriver
    $LogsPath = $global:BuildMedia.LogsPath

    if ($WinPEDriver) {
        Write-OSDeployCoreProgress 'WinPEDriver: Add-WindowsDriver'
        foreach ($DriverPath in $WinPEDriver) {
            if (Test-Path $DriverPath) {
                Write-Host -ForegroundColor DarkGray "$DriverPath"
                $CurrentLog = "$LogsPath\$((Get-Date).ToString('yyMMdd-HHmmss'))-Add-WindowsDriver.log"
                try {
                    $null = Add-WindowsDriver -Path $MountPath -Driver $DriverPath -ForceUnsigned -Recurse -LogPath "$CurrentLog" -ErrorAction Stop
                }
                catch {
                    Write-Error "Driver failed to install from: $DriverPath"
                    Write-Error "Dism Log: $CurrentLog"
                }
            }
            else {
                Write-Warning "WinPEDriver not found: $DriverPath"
            }
        }
    }
}