private/BootMedia/Steps/Select-OSDeployCoreBuildDriver.ps1

#Requires -PSEdition Core

function Select-OSDeployCoreBuildDriver {
    <#
    .SYNOPSIS
        Displays WinPE driver folders in an Out-GridView picker for build selection.
 
    .DESCRIPTION
        Enumerates WinPE driver folders from both the OSDeployCore library (default + user)
        and presents them in an Out-GridView for multi-selection.
 
    .PARAMETER Architecture
        Filter drivers by architecture (amd64 or arm64).
 
    .PARAMETER SkipWifiDrivers
        Exclude driver folders whose name matches 'wifi' or 'wireless' before showing the
        picker. Pass this when building from ADK WinPE, which does not support wireless
        hardware.
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

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

        [System.Management.Automation.SwitchParameter]
        $SkipWifiDrivers
    )

    $driverItems = @()
    $driverItems += Get-ChildItem -Path "$script:OSDeployCoreRepositoryPath\winpe-drivers\*\*" -Directory -ErrorAction SilentlyContinue |
        Select-Object @{Name = 'Type'; Expression = { 'winpe-driver' } },
            Name,
            @{Name = 'Architecture'; Expression = { $_.Parent.Name } },
            FullName,
            LastWriteTime

    # Filter to valid architectures
    $driverItems = $driverItems | Where-Object {
        ($_.Architecture -eq 'amd64') -or ($_.Architecture -eq 'arm64')
    }

    if ($Architecture) {
        $driverItems = $driverItems | Where-Object { $_.Architecture -eq $Architecture }
    }

    if ($SkipWifiDrivers) {
        $driverItems = $driverItems | Where-Object { $_.Name -notmatch 'wifi|wireless' }
    }

    $driverItems = $driverItems | Sort-Object -Property Name, FullName

    if ($driverItems -and $driverItems.Count -gt 0) {
        Write-OSDeployCoreProgress 'Select WinPE Drivers to add to this BootImage (Cancel to skip)'
        $selected = $driverItems |
            Out-GridView -PassThru -Title 'Select WinPE Drivers to add to this BootImage (Cancel to skip)'

        return $selected
    }

    return $null
}