private/CoreDrivers/CoreWinPEDriver/Expand-CoreWinPEDriverZip.ps1

#Requires -PSEdition Core

function Expand-CoreWinPEDriverZip {
    <#
    .SYNOPSIS
        Extracts the contents of a .zip file.
 
    .DESCRIPTION
        Internal helper that wraps Expand-Archive to extract zip files.
        Returns the destination directory on success.
 
    .PARAMETER Path
        Full path to the .zip file.
 
    .PARAMETER DestinationPath
        Directory where contents will be extracted.
 
    .PARAMETER Force
        Overwrite existing files in the destination.
 
    .OUTPUTS
        [System.IO.DirectoryInfo] The extraction destination directory.
 
    .NOTES
 
    Dependencies:
      Windows Features: Windows ADK WinPE Addon
      .NET Classes: [System.IO.DirectoryInfo], [System.IO.FileNotFoundException], [System.Management.Automation.ErrorCategory], [System.Management.Automation.ErrorRecord]
    #>

    [CmdletBinding()]
    [OutputType([System.IO.DirectoryInfo])]
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$Path,

        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$DestinationPath,

        [Parameter()]
        [switch]$Force
    )

    if (-not (Test-Path -Path $Path)) {
        $PSCmdlet.ThrowTerminatingError(
            [System.Management.Automation.ErrorRecord]::new(
                [System.IO.FileNotFoundException]::new("Zip file not found: $Path"),
                'ZipFileNotFound',
                [System.Management.Automation.ErrorCategory]::ObjectNotFound,
                $Path
            )
        )
    }

    if (-not (Test-Path -Path $DestinationPath)) {
        New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null
    }

    Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Extracting zip: $Path -> $DestinationPath"

    $expandParams = @{
        Path            = $Path
        DestinationPath = $DestinationPath
        ErrorAction     = 'Stop'
    }
    if ($Force) {
        $expandParams['Force'] = $true
    }

    Expand-Archive @expandParams

    Write-Verbose "[$(Get-Date -format s)] [$($MyInvocation.MyCommand.Name)] Zip extraction complete: $DestinationPath"
    Get-Item -Path $DestinationPath
}