-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdownload.ps1
More file actions
51 lines (43 loc) · 1.25 KB
/
download.ps1
File metadata and controls
51 lines (43 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
param (
[Parameter(Mandatory=$true)]
[string]$FileName,
[Parameter(Mandatory=$true)]
[string]$Url,
[Parameter(Mandatory=$true)]
[string]$Checksum
)
$DataDir = "./data"
$FilePath = "$DataDir\$FileName.zip"
function Get-Checksum {
param (
[string]$FilePath
)
$hash = Get-FileHash -Path $FilePath -Algorithm SHA256
return $hash.Hash
}
function Get-File {
param (
[string]$FileName,
[string]$FileUrl,
[string]$ExpectedChecksum,
[string]$FilePath
)
Write-Host("Trying to download $FileName data...")
if (Test-Path -Path $FilePath) {
$checksum = Get-Checksum -FilePath $FilePath
if ($checksum -eq $ExpectedChecksum) {
# Checksum matches. No need to re-download.
Write-Output "$FileName already exists."
} else {
Write-Output "Checksum does not match. Re-downloading $FileName..."
Invoke-WebRequest -Uri $FileUrl -OutFile $FilePath
}
} else {
Write-Output "$FileName does not exist. Downloading..."
Invoke-WebRequest -Uri $FileUrl -OutFile $FilePath
}
}
Get-File -FileName $FileName `
-FileUrl $Url `
-ExpectedChecksum $Checksum `
-FilePath $FilePath