public/Get-OSDeployWinPEDrivers.ps1

#Requires -PSEdition Core
#Requires -Version 7.4

function Get-OSDeployWinPEDrivers {
    <#
    .SYNOPSIS
        Returns WinPE driver folders from the OSDeployCore library.
 
    .DESCRIPTION
        Enumerates the amd64 and arm64 WinPE driver folders under both the module-managed
        library (winpe-drivers) and user-managed library (library\user) beneath
        $env:ProgramData\OSDeployCore\Repository. Returns a [System.IO.DirectoryInfo] object for each
        discovered folder via Get-Item.
 
        Results are sorted by Name then FullName. Use -Architecture to limit results to a
        single architecture, -SkipWifiDrivers to exclude wireless-related folders, and -Interactive to
        interactively select folders before output is returned.
 
    .PARAMETER Architecture
        Limits results to the specified architecture (amd64 or arm64). When omitted, folders
        from both architectures are returned.
 
    .PARAMETER SkipWifiDrivers
        Excludes any folder whose name contains 'wifi' or 'wireless' (case-insensitive).
 
    .PARAMETER Interactive
        Presents the discovered folders in an Out-GridView picker. Only the rows selected
        before clicking OK are passed through to output.
 
    .EXAMPLE
        PS> Get-OSDeployWinPEDrivers
        Returns all WinPE driver folders for both architectures from both default and user libraries.
 
    .EXAMPLE
        PS> Get-OSDeployWinPEDrivers -Architecture amd64
        Returns only amd64 WinPE driver folders.
 
    .EXAMPLE
        PS> Get-OSDeployWinPEDrivers -Architecture amd64 -SkipWifiDrivers
        Returns amd64 WinPE driver folders, excluding any Wi-Fi or Wireless entries.
 
    .EXAMPLE
        PS> Get-OSDeployWinPEDrivers -Interactive
        Opens an Out-GridView picker and returns only the folders selected by the user.
 
    .OUTPUTS
        [System.IO.DirectoryInfo]
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

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

        [Parameter()]
        [switch]$SkipWifiDrivers,

        [Parameter()]
        [switch]$Interactive
    )

    begin {
        Write-OSDeployBanner
    }
    process {
        $architectures = if ($Architecture) { @($Architecture) } else { @('amd64', 'arm64') }

        $driverItems = [System.Collections.Generic.List[PSCustomObject]]::new()

        foreach ($arch in $architectures) {
            $driverPath = Join-Path $script:OSDeployCoreRepositoryPath 'winpe-drivers' $arch
            if (Test-Path -Path $driverPath -PathType Container) {
                Get-ChildItem -Path $driverPath -Directory | ForEach-Object {
                    $driverItems.Add([PSCustomObject]@{
                            Type          = 'winpe-driver'
                            Name          = $_.Name
                            Architecture  = $arch
                            FullName      = $_.FullName
                            LastWriteTime = $_.LastWriteTime
                        })
                }
            }
        }

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

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

        if ($Interactive) {
            $driverItems = $driverItems | Out-GridView -Title 'Select WinPE Driver to add to this BootImage (Cancel to skip)' -PassThru
        }

        foreach ($item in $driverItems) {
            Get-Item -Path $item.FullName
        }
    }
}