added retry logic for download

This commit is contained in:
Dariy.Nurgaleev
2020-03-18 00:46:51 +07:00
parent b2c676b3e3
commit 81872a6a71

View File

@@ -25,10 +25,37 @@ function Start-Task {
function Start-DownloadSQLExpress {
param(
[String]$InstallerUrl,
[String]$InstallerPath
[String]$InstallerPath,
[int] $retries = 10
)
Write-Host "Download SQL Express web-installer from: $InstallerUrl"
(New-Object System.Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath)
Write-Host "Downloading SQL Express web-installer from: $InstallerUrl"
# In case of any errors -try to download package several times
while($retries -gt 0)
{
try
{
Write-Host "Downloading SQL Express installer..."
(New-Object System.Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath)
break
}
catch
{
Write-Host "There is an error during SQL Express downloading"
$_
$retries--
if ($retries -eq 0)
{
Write-Host "File can't be downloaded"
$_
exit 1
}
Write-Host "Waiting 30 seconds before retrying. Retries left: $retries"
Start-Sleep -Seconds 30
}
}
Write-Host "SQL Express has been successfully downladed from the link: $InstallerUrl"
}