Files
runner-images/images/win/scripts/Installers/Install-SQLExpress.ps1
T

79 lines
3.0 KiB
PowerShell
Raw Normal View History

2020-03-17 23:46:14 +07:00
################################################################################
## File: Install-SQLExpress.ps1
## Desc: Install SQL Express for Windows
################################################################################
2020-03-19 18:48:52 +07:00
Import-Module -Name ImageHelpers -Force;
2020-03-19 01:56:11 +07:00
function Download-FullSQLPackage {
param(
[String]$InstallerPath,
[String]$DownloadPath,
[String]$Arguments = ("/MEDIAPATH=$DownloadPath", "/MEDIATYPE=Core","/Action=Download", "/QUIET")
2020-03-19 01:56:11 +07:00
)
Write-Host "Downloading full package to $DownloadPath..."
2020-03-19 01:56:11 +07:00
$process = Start-Process -FilePath $InstallerPath -ArgumentList $Arguments -Wait -PassThru
$exitCode = $process.ExitCode
if ($exitCode -eq 0)
{
Write-Host -Object "Full SQL Express package has been successfully downloaded to $DownloadPath : ExitCode: $exitCode"
2020-03-19 01:56:11 +07:00
}
else
{
Write-Host -Object "Full package downloading process was unsuccessful. Exit code: $exitCode."
exit $exitCode
}
}
function Unpack-SQLInstaller {
2020-03-17 21:47:47 +07:00
param(
[String]$InstallPath,
2020-03-19 01:56:11 +07:00
[String]$Arguments = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS")
2020-03-17 21:47:47 +07:00
)
2020-03-20 01:56:57 +07:00
Write-Host "Start unpacking procedure to $InstallPath..."
2020-03-17 21:47:47 +07:00
$process = Start-Process -FilePath $InstallPath -ArgumentList $Arguments -Wait -PassThru
$exitCode = $process.ExitCode
# Exit code -2067529716 is added since SQL Unpack procedure returns it on success.
2020-03-17 22:56:55 +07:00
if ($exitCode -eq 0 -or $exitCode -eq -2067529716)
2020-03-17 21:47:47 +07:00
{
2020-03-19 01:56:11 +07:00
Write-Host -Object "SQL installer unpacking has been completed."
2020-03-17 21:47:47 +07:00
}
else
{
2020-03-19 01:56:11 +07:00
Write-Host -Object "SQL installer unpacking was interrupted : $exitCode."
2020-03-17 21:47:47 +07:00
exit $exitCode
}
}
2020-03-19 01:56:11 +07:00
function Start-Installer {
param(
2020-03-20 18:48:51 +07:00
[String]$InstallerPath,
2020-03-19 01:56:11 +07:00
[String]$Arguments = ("/Q", "/IACCEPTSQLSERVERLICENSETERMS", "/Action=Install", "/INSTANCEID=SQL2019", "/INSTANCENAME=SQL2019", "/SECURITYMODE=SQL", "/SAPWD=P@ssword!!", "/TCPENABLED=1")
)
2020-03-20 01:56:57 +07:00
Write-Host "Installating SQL Express..."
2020-03-20 18:48:51 +07:00
$process = Start-Process -FilePath $InstallerPath -ArgumentList $Arguments -Wait -PassThru
2020-03-19 01:56:11 +07:00
$exitCode = $process.ExitCode
if ($exitCode -eq 0)
{
Write-Host -Object "SQL Express has been successfully installed: ExitCode: $exitCode"
}
else
{
Write-Host -Object "Installation procedure was not correctly completed. Exit code: $exitCode."
exit $exitCode
}
}
2020-03-24 12:50:18 +07:00
#Main function
2020-03-12 21:22:54 +07:00
$installerUrl = "https://go.microsoft.com/fwlink/?linkid=866658"
2020-03-24 15:11:15 +07:00
$downloadPath = "C:\SQLInstall"
2020-03-12 21:22:54 +07:00
$setupPath = Join-Path $downloadPath "SQLEXPR_x64_ENU"
2020-03-24 17:23:59 +07:00
#Create directory for temporary files
New-Item -Path $downloadPath -ItemType Directory
2020-03-19 01:56:11 +07:00
Set-Location -Path $downloadPath
2020-03-24 17:35:11 +07:00
$installerPath = Start-DownloadWithRetry -Url $installerUrl -DownloadPath $downloadPath -Name "SQL2019-SSEI-Expr.exe"
Download-FullSQLPackage -InstallerPath $installerPath -DownloadPath $downloadPath
2020-03-20 19:09:06 +07:00
Unpack-SQLInstaller -InstallPath "$setupPath.exe"
2020-03-22 20:17:57 +07:00
$resultPath = Join-Path $setupPath "SETUP.exe"
2020-03-24 16:28:43 +07:00
Start-Installer -InstallerPath $resultPath
2020-03-24 17:23:59 +07:00
#Cleanup folder with installation packages.
Remove-Item $downloadPath -Recurse -Force