public/Update-OSDeployWinPEDrivers.ps1

#Requires -PSEdition Core
#Requires -Version 7.4

function Update-OSDeployWinPEDrivers {
    <#
    .SYNOPSIS
        Refreshes the WinPE driver catalog and downloads the selected driver packages.
 
    .DESCRIPTION
        This is the supported public entrypoint for the OSDeployCore module. It refreshes
        the requested catalog sources, resolves the matching WinPE driver packages, and
        downloads and expands the selected packages to $env:ProgramData\OSDeployCore.
 
        By default an Out-GridView picker is shown so the operator can choose which packages
        to download. Use -NonInteractive to skip the picker and process all matching packages
        directly without prompting.
 
    .PARAMETER Name
        One or more source names to refresh and present for download.
 
    .PARAMETER Force
        Re-download driver packages even when a matching cached file already exists.
 
    .PARAMETER NonInteractive
        Skip the Out-GridView picker and process all matching packages directly without
        prompting. When omitted, an Out-GridView picker is presented by default.
 
    .PARAMETER SkipWifiDrivers
        Exclude Wi-Fi driver packages (intel-wifi, microsoft-windows-wifi) from download
        and processing. ADK WinPE does not support wireless hardware, so Wi-Fi drivers are
        only needed when a WinRE-based boot image will be built. When no imported OS sources
        are present, this switch is enforced automatically.
 
    .PARAMETER DownloadOnly
        Download driver packages to the cache without expanding them. The downloaded file
        is saved to $env:ProgramData\OSDeployCore\cache\downloads\<vendor>\ but the
        expand step is skipped and no package.json metadata file is written.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -Name 'dell'
        Refreshes the dell catalog and opens the Out-GridView picker for dell packages.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -Name 'dell', 'hp' -WhatIf
        Shows the catalog refresh and download actions for dell and hp without executing them.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers
        Refreshes all configured sources and opens the Out-GridView picker for all available packages.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -Name 'dell' -NonInteractive
        Refreshes the dell catalog and downloads all matching packages without prompting.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -Name 'dell' -NonInteractive -WhatIf
        Refreshes the dell catalog and previews the non-interactive download workflow without executing.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -Name 'dell' -DownloadOnly
        Refreshes the dell catalog and downloads the .cab without expanding it.
 
    .EXAMPLE
        PS> Update-OSDeployWinPEDrivers -SkipWifiDrivers
        Refreshes all configured sources, excludes Wi-Fi packages, and opens the Out-GridView picker.
 
    .OUTPUTS
        [System.IO.FileInfo] The downloaded file(s).
 
    .NOTES
        Author: David Segura
        Version: 0.1.0
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType([System.IO.FileInfo])]
    param (
        [Parameter(Position = 0)]
        [ArgumentCompleter({
            param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
            $global:OSDeployModule.WinPEDrivers.PSObject.Properties |
                Where-Object { ($_.Value.UpdateUri -or $_.Value.DownloadUri) -and -not $_.Value.Disabled -and $_.Name -like "$wordToComplete*" } |
                ForEach-Object { [System.Management.Automation.CompletionResult]::new($_.Name) }
        })]
        [string[]]$Name,

        [Parameter()]
        [switch]$Force,

        [Parameter()]
        [switch]$NonInteractive,

        [Parameter()]
        [switch]$SkipWifiDrivers,

        [Parameter()]
        [switch]$DownloadOnly
    )

    begin {
        Write-OSDeployBanner
        Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Starting"
        Write-OSDeployWinPEDriversProgress "Starting OSDeployCore Driver Update ..."
        Initialize-OSDeployCoreWinPEDrivers

        if (-not $SkipWifiDrivers) {
            $importedSources = Get-OSDeployCoreWinRESource -ErrorAction SilentlyContinue
            if (-not $importedSources) {
                $SkipWifiDrivers = $true
                Write-Warning "No imported OS sources found. Wi-Fi drivers require WinRE (ADK WinPE does not support wireless hardware) and will be skipped."
            }
        }
    }

    process {
        $targetLabel = if ($Name) {
            $Name -join ', '
        }
        else {
            'all refreshable sources'
        }

        $commonParameters = @{ Confirm = $false }
        if ($WhatIfPreference) {
            $commonParameters.WhatIf = $true
        }

        $catalogParameters = @{}
        if ($Name) {
            $catalogParameters.Name = $Name
        }
        if ($Force) {
            $catalogParameters.Force = $true
        }

        $saveParameters = @{ SkipCatalogRefresh = $true; Confirm = $false }
        if ($Name) {
            $saveParameters.Name = $Name
        }
        if ($Force) {
            $saveParameters.Force = $true
        }
        if (-not $NonInteractive) {
            $saveParameters.Interactive = $true
        }
        if ($SkipWifiDrivers) {
            $saveParameters.SkipWifiDrivers = $true
        }
        if ($DownloadOnly) {
            $saveParameters.DownloadOnly = $true
        }
        if ($WhatIfPreference) {
            $saveParameters.WhatIf = $true
        }

        if ($WhatIfPreference) {
            Update-OSDeployWinPEDriversCatalog @catalogParameters @commonParameters | Out-Null
            Save-CloudWinPEDriver @saveParameters
            return
        }

        if ($PSCmdlet.ShouldProcess($targetLabel, 'Refresh catalog and save WinPE drivers for BootMedia')) {
            Update-OSDeployWinPEDriversCatalog @catalogParameters @commonParameters | Out-Null
            Save-CloudWinPEDriver @saveParameters
        }
    }

    end {
        Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Complete"
    }
}