From 71dfd431bdb84841425601f81c44b02644437ec5 Mon Sep 17 00:00:00 2001 From: "Dariy.Nurgaleev" Date: Thu, 19 Mar 2020 18:48:52 +0700 Subject: [PATCH] added DownloadWithRetry function --- .../scripts/Installers/Install-SQLExpress.ps1 | 41 +------------------ 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/images/win/scripts/Installers/Install-SQLExpress.ps1 b/images/win/scripts/Installers/Install-SQLExpress.ps1 index d39f4f7b..ed6a6606 100644 --- a/images/win/scripts/Installers/Install-SQLExpress.ps1 +++ b/images/win/scripts/Installers/Install-SQLExpress.ps1 @@ -2,6 +2,7 @@ ## File: Install-SQLExpress.ps1 ## Desc: Install SQL Express for Windows ################################################################################ +Import-Module -Name ImageHelpers -Force; function Download-FullSQLPackage { param( @@ -60,52 +61,14 @@ function Start-Installer { } } - -function Start-DownloadSQLExpress { - param( - [String]$InstallerUrl, - [String]$InstallerPath, - [int] $retries = 10 - ) - 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" -} #default variables for functions. $installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658" -$installerPath = "${env:Temp}\SQL2019-SSEI-Expr.exe" $downloadPath = "C:\SQLEXPRESS2019" $setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU" #Set default location for proper script execution Set-Location -Path $downloadPath #Download installer for SQL Express -Start-DownloadSQLExpress -InstallerUrl $installerUrl -InstallerPath $installerPath +$installerPath = Start-DownloadWithRetry -Url "https://go.microsoft.com/fwlink/?linkid=866658" -Name SQL2019-SSEI-Expr.exe #Download full SQL Express package Download-FullSQLPackage -InstallerPath $installerPath #Unpack SQL Express Installer