private/Save-WinPEDriverPackageIntelWifi.ps1

#Requires -PSEdition Core

function Save-WinPEDriverPackageIntelWifi {
    <#
    .SYNOPSIS
        Downloads and expands an Intel wireless WinPE driver package
 
    .DESCRIPTION
        Downloads an Intel PROSet/Wireless IT Administrators ZIP package to the OSDeployCore
        download cache and verifies its SHA256 checksum through
        Invoke-WinPEDriverPackageDownload. Unless DownloadOnly is specified, the function
        expands the archive into the architecture-specific managed winpedrivers cache
        folder when that folder contains no files.
 
    .PARAMETER DriverPackage
        Specifies the OSDeployWinPEDriver.Package object to download. The object supplies
        the package name, version, architecture, URIs, filename, and SHA256 checksum.
 
    .PARAMETER Force
        Downloads the package again and passes Force to ZIP expansion.
 
    .PARAMETER DownloadOnly
        Returns after downloading the archive without creating or updating expanded driver content.
 
    .EXAMPLE
        PS> $package = Get-WinPEDriverPackageCore | Where-Object Name -Match 'Intel.*WiFi|Intel.*Wireless' | Select-Object -First 1; Save-WinPEDriverPackageIntelWifi -DriverPackage $package
 
        Downloads the first matching Intel wireless package and expands it when needed.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.IO.FileInfo. Returns the downloaded ZIP file, or no object when the download fails.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-28
 
        Assumes the OSDeployCore cache and Boot-Assets paths are initialized and writable.
 
    .LINK
        Save-WinPEDriverPackageCore
    #>

    [CmdletBinding()]
    [OutputType([System.IO.FileInfo])]
    param (
        [Parameter(Mandatory)]
        [PSTypeName('OSDeployWinPEDriver.Package')]
        [PSCustomObject]$DriverPackage,

        [Parameter()]
        [switch]$Force,

        [Parameter()]
        [switch]$DownloadOnly
    )

    $package     = $DriverPackage
    $idPrefix    = ($package.Name -split '-')[0]
    $downloadDir = Join-Path $script:OSDeployCoreDownloadsPath $idPrefix
    $targetPath  = Join-Path $downloadDir $package.FileName
    $driverDir   = Join-Path $script:OSDeployBootAssetsPath "winpedrivers-$($package.Architecture)" |
                   Join-Path -ChildPath "$($package.Name)-$($package.Version)"

    Write-HostDateTimeDarkGray -Message "Starting $($package.Name)"

    # Download
    $downloadedFile = Invoke-WinPEDriverPackageDownload `
        -Uri             $package.DownloadUri `
        -DestinationPath $targetPath `
        -SearchUri       $package.UpdateUri `
        -ExpectedSHA256  $package.Checksums.SHA256 `
        -Force:$Force

    if (-not $downloadedFile) {
        return
    }

    if ($DownloadOnly) {
        return $downloadedFile
    }

    # Expand zip
    $expandedFiles = Get-ChildItem -Path $driverDir -Recurse -File -ErrorAction SilentlyContinue
    if (-not $expandedFiles) {
        if (-not (Test-Path -Path $driverDir)) {
            New-Item -ItemType Directory -Path $driverDir -Force | Out-Null
        }
        Write-HostDateTimeDarkGray -Message "Expand: $targetPath"
        Write-HostDateTimeDarkGray -Message "Output: $driverDir"
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Expanding '$($package.FileName)' to '$driverDir'"
        Expand-WinPEDriverPackageZip -Path $targetPath -DestinationPath $driverDir -Force:$Force
    }
    else {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] '$driverDir' already contains expanded files. Skipping expansion."
    }

    $downloadedFile
}