From cde2e7d56d1b6d7a6cd46fa0793db9ebcec9d977 Mon Sep 17 00:00:00 2001 From: "Dariy.Nurgaleev" Date: Thu, 12 Mar 2020 21:22:54 +0700 Subject: [PATCH] added SQL Express install step --- .../scripts/Installers/Install-SQLExpress.ps1 | 20 +++++++++++++++++++ .../Installers/Validate-SQLExpress.ps1 | 15 ++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 images/win/scripts/Installers/Install-SQLExpress.ps1 create mode 100644 images/win/scripts/Installers/Validate-SQLExpress.ps1 diff --git a/images/win/scripts/Installers/Install-SQLExpress.ps1 b/images/win/scripts/Installers/Install-SQLExpress.ps1 new file mode 100644 index 00000000..4cb6deae --- /dev/null +++ b/images/win/scripts/Installers/Install-SQLExpress.ps1 @@ -0,0 +1,20 @@ +#Download web-installer +$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658" +$installerName = "SQL2019-SSEI-Expr.exe" +$installerPath = "${env:Temp}\$installerName" +Write-Host "Download web-installer" +(New-Object System.Net.WebClient).DownloadFile($installerUrl, $installerPath) +#use web-installer to download setup package +$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") +Write-Host "Downloading SQL Express setup package" +Start-Process -FilePath $installerPath -ArgumentList $downloadArgs -Wait -PassThru +#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 +Write-Host "Run SQL Express setup package" +Start-Process -FilePath "$setupPath/SETUP.exe" -ArgumentList $args -Wait -PassThru \ No newline at end of file diff --git a/images/win/scripts/Installers/Validate-SQLExpress.ps1 b/images/win/scripts/Installers/Validate-SQLExpress.ps1 new file mode 100644 index 00000000..8a0b78fd --- /dev/null +++ b/images/win/scripts/Installers/Validate-SQLExpress.ps1 @@ -0,0 +1,15 @@ +$sqlConn = New-Object System.Data.SqlClient.SqlConnection +$sqlConn.ConnectionString = "Server=$env:computername\SQL2019;Integrated Security=false;User ID=sa; Password=P@ssword!!" +$sqlConn.Open() +$str1="" +$sqlConn.State +IF (Compare-Object $sqlConn.State $str1) +{ +Write-Host "Failed attempt" +exit 1 +} +ELSE +{ +Write-Host "Success" +exit 0 +} \ No newline at end of file