private/Save-WinPEDriverPackageDell.ps1

#Requires -PSEdition Core

function Save-WinPEDriverPackageDell {
    <#
    .SYNOPSIS
        Downloads and expands a Dell WinPE driver package
 
    .DESCRIPTION
        Downloads a Dell cabinet package to the OSDeployCore download cache and verifies
        its SHA256 checksum through Invoke-WinPEDriverPackageDownload. Unless DownloadOnly
        is specified, the function expands the cabinet into the architecture-specific
        managed architecture-specific winpedrivers 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 even when a cached file passes checksum validation.
 
    .PARAMETER DownloadOnly
        Returns after downloading the cabinet without creating or updating expanded driver content.
 
    .EXAMPLE
        PS> $package = Get-WinPEDriverPackageCore | Where-Object Name -Match '^Dell' | Select-Object -First 1; Save-WinPEDriverPackageDell -DriverPackage $package
 
        Downloads the first Dell package and expands it when its managed driver folder contains no files.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.IO.FileInfo. Returns the downloaded cabinet 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)"

    # 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 if directory is empty or missing
    $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-WinPEDriverPackageCab -Path $targetPath -DestinationPath $driverDir
    }
    else {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] '$driverDir' already contains expanded files. Skipping expansion."
    }

    $downloadedFile
}