From debb478679eee046a9b0a86c8daee750ea56f72f Mon Sep 17 00:00:00 2001 From: "Dariy.Nurgaleev" Date: Tue, 17 Mar 2020 01:28:14 +0700 Subject: [PATCH] SQLExpress installation full process --- images/win/Windows2016-Azure.json | 14 +++++++ images/win/Windows2019-Azure.json | 4 +- .../scripts/Installers/Install-SQLExpress.ps1 | 42 +++++++++++++++++-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/images/win/Windows2016-Azure.json b/images/win/Windows2016-Azure.json index fcb0ed4c..b4033529 100644 --- a/images/win/Windows2016-Azure.json +++ b/images/win/Windows2016-Azure.json @@ -296,6 +296,12 @@ "{{ template_dir }}/scripts/Installers/Install-Bazel.ps1" ] }, + { + "type": "powershell", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Validate-SQLExpress.ps1" + ] + }, { "type": "powershell", "scripts":[ @@ -455,6 +461,14 @@ "{{ template_dir }}/scripts/Installers/Install-MysqlCli.ps1" ] }, + { + "type": "powershell", + "elevated_user": "SYSTEM", + "elevated_password": "", + "scripts":[ + "{{ template_dir }}/scripts/Installers/Install-SQLExpress.ps1" + ] + }, { "type": "powershell", "scripts":[ diff --git a/images/win/Windows2019-Azure.json b/images/win/Windows2019-Azure.json index 732d417d..20711d80 100644 --- a/images/win/Windows2019-Azure.json +++ b/images/win/Windows2019-Azure.json @@ -438,8 +438,10 @@ }, { "type": "powershell", + "elevated_user": "SYSTEM", + "elevated_password": "", "scripts":[ - "{{ template_dir }}/scripts/Installers/Windows2019/Install-SQLExpress.ps1" + "{{ template_dir }}/scripts/Installers/Install-SQLExpress.ps1" ] }, { diff --git a/images/win/scripts/Installers/Install-SQLExpress.ps1 b/images/win/scripts/Installers/Install-SQLExpress.ps1 index 4cb6deae..70768729 100644 --- a/images/win/scripts/Installers/Install-SQLExpress.ps1 +++ b/images/win/scripts/Installers/Install-SQLExpress.ps1 @@ -1,4 +1,5 @@ #Download web-installer +Set-Item .\MaxMemoryPerShellMB 4096 $installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658" $installerName = "SQL2019-SSEI-Expr.exe" $installerPath = "${env:Temp}\$installerName" @@ -9,12 +10,45 @@ $downloadPath = "C:\SQLEXPRESS2019" $setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU" $downloadArgs = ("/MEDIAPATH=$downloadPath", "/MEDIATYPE=Core","/Action=Download", "/QUIET") $installArgs = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS") -$args = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS", "/Action=Install", "/INSTANCEID=SQL2020", "/INSTANCENAME=SQL2020", "/SECURITYMODE=SQL", "/SAPWD=P@ssword!!", "/TCPENABLED=1") +$args = ("/c", "$setupPath/SETUP.exe", "/Q", "/IACCEPTSQLSERVERLICENSETERMS", "/Action=Install", "/INSTANCEID=SQL2019", "/INSTANCENAME=SQL2019", "/SECURITYMODE=SQL", "/SAPWD=P@ssword!!", "/TCPENABLED=1") Write-Host "Downloading SQL Express setup package" -Start-Process -FilePath $installerPath -ArgumentList $downloadArgs -Wait -PassThru +$process = Start-Process -FilePath $installerPath -ArgumentList $downloadArgs -Wait -PassThru +$exitCode = $process.ExitCode +if ($exitCode -eq 0) +{ + Write-Host -Object 'Downloaded successfully' + Write-Host $exitCode +} + else +{ + Write-Host -Object "Non zero exit code returned by the installation process : $exitCode." + exit $exitCode +} #Unpack and run setup-package Set-Location -Path $downloadPath Write-Host "Unpack SQL Express setup package" -Start-Process -FilePath "$setupPath.exe" -ArgumentList $installArgs -Wait -PassThru +$process = Start-Process -FilePath "$setupPath.exe" -ArgumentList $installArgs -Wait -PassThru +$exitCode = $process.ExitCode +if ($exitCode -eq 0) +{ + Write-Host -Object 'Unpacked successfully' + Write-Host $exitCode +} + else +{ + Write-Host -Object "Non zero exit code returned by the installation process : $exitCode." + Write-Host $exitCode +} Write-Host "Run SQL Express setup package" -Start-Process -FilePath "$setupPath/SETUP.exe" -ArgumentList $args -Wait -PassThru \ No newline at end of file +$process = Start-Process -FilePath cmd.exe -ArgumentList $args -Wait -PassThru +$exitCode = $process.ExitCode +if ($exitCode -eq 0) +{ + Write-Host -Object 'Installed successfully' + Write-Host $exitCode +} + else +{ + Write-Host -Object "Non zero exit code returned by the installation process : $exitCode." + exit $exitCode +} \ No newline at end of file