17 lines
703 B
PowerShell
17 lines
703 B
PowerShell
# Usage: .\download.ps1 https://www.a.url/to/download filename_for_downloaded.file
|
|
# Usage: .\download.ps1 https://www.a.url/to/download filename_for_downloaded.file a_username a_password
|
|
$URL=$args[0]
|
|
$FILENAME=$args[1]
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
if ($args.count -gt 2) {
|
|
$USERNAME=$args[2]
|
|
$PASSWORD=$args[3]
|
|
|
|
$AUTH_PAIR=[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($USERNAME):$($PASSWORD)"))
|
|
$AUTH_HEADERS=@{Authorization="Basic $AUTH_PAIR"}
|
|
Invoke-WebRequest -Uri "${URL}" -OutFile "${FILENAME}" -Headers ${AUTH_HEADERS}
|
|
} else {
|
|
Invoke-WebRequest -Uri "${URL}" -OutFile "${FILENAME}"
|
|
}
|