Last active
August 2, 2024 08:45
-
-
Save lowleveldesign/9d89466ce08c951bade0f6e30b0bf4cc to your computer and use it in GitHub Desktop.
Download a file and unzip it in some folder if it's an archive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory = $true)][string]$Uri, | |
[Parameter(Mandatory = $true)][string]$TargetFolderPath | |
) | |
$ErrorActionPreference = "Stop" | |
$FileName = Split-Path -Path $Uri -Leaf | |
$DownloadFilePath = Join-Path $env:TEMP $FileName | |
Write-Host "Downloading file from $Uri to $DownloadFilePath" | |
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $DownloadFilePath | |
if ($FileName.EndsWith(".zip")) { | |
Expand-Archive -Force -LiteralPath $DownloadFilePath -DestinationPath "$TargetFolderPath" | |
Remove-Item -LiteralPath $DownloadFilePath | |
} else { | |
Move-Item -Force -LiteralPath $DownloadFilePath -Destination $TargetFolderPath | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment