added DownloadWithRetry function
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
## File: Install-SQLExpress.ps1
|
## File: Install-SQLExpress.ps1
|
||||||
## Desc: Install SQL Express for Windows
|
## Desc: Install SQL Express for Windows
|
||||||
################################################################################
|
################################################################################
|
||||||
|
Import-Module -Name ImageHelpers -Force;
|
||||||
|
|
||||||
function Download-FullSQLPackage {
|
function Download-FullSQLPackage {
|
||||||
param(
|
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.
|
#default variables for functions.
|
||||||
$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658"
|
$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658"
|
||||||
$installerPath = "${env:Temp}\SQL2019-SSEI-Expr.exe"
|
|
||||||
$downloadPath = "C:\SQLEXPRESS2019"
|
$downloadPath = "C:\SQLEXPRESS2019"
|
||||||
$setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU"
|
$setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU"
|
||||||
#Set default location for proper script execution
|
#Set default location for proper script execution
|
||||||
Set-Location -Path $downloadPath
|
Set-Location -Path $downloadPath
|
||||||
#Download installer for SQL Express
|
#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 full SQL Express package
|
||||||
Download-FullSQLPackage -InstallerPath $installerPath
|
Download-FullSQLPackage -InstallerPath $installerPath
|
||||||
#Unpack SQL Express Installer
|
#Unpack SQL Express Installer
|
||||||
|
|||||||
Reference in New Issue
Block a user