misc/Download-And-ExtractArchive.ps1
<#
.SYNOPSIS Downloads a ZIP archive from a specified URL and extracts it to a destination directory. .DESCRIPTION This function downloads a ZIP archive from the provided URL and extracts its contents to the specified destination directory. It uses the `Invoke-WebRequest` cmdlet to download the file and the `Expand-Archive` cmdlet to extract it. .PARAMETER zipUrl The URL of the ZIP archive to be downloaded. .PARAMETER destination The path to the directory where the archive will be extracted. .EXAMPLE $destination = "$(Build.ArtifactStagingDirectory)\allapps" Download-And-ExtractArchive -zipUrl "https://smartartifacts.blob.core.windows.net/localization-apps/ua/latest.zip$(AppStorageSAS)" -destination $destination #> function Download-And-ExtractArchive { param ( [Parameter(Mandatory = $true)] [string]$zipUrl, [Parameter(Mandatory = $true)] [string]$destination ) try { $tempDir = "$Env:BUILD_ARTIFACTSTAGINGDIRECTORY" $zipPath = Join-Path -Path $tempDir -ChildPath "apps.zip" Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath Expand-Archive -Path $zipPath -DestinationPath $destination -Force } catch { Write-Error "An error occurred: $_" } } |