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

53 lines
1.8 KiB
PowerShell
Raw Normal View History

2020-03-17 23:46:14 +07:00
################################################################################
## File: Validate-SQLExpress.ps1
## Desc: Validate Microsoft SQL Express installation
################################################################################
2020-03-19 01:36:41 +07:00
#Parameters for database access
$sqlUser = "sa"
$sqlPassword = "P@ssword!!"
$sqlInstance = "SQL2019"
2020-03-17 23:22:20 +07:00
function Test-SqlConnection {
param(
[Parameter(Mandatory)]
[string]$ServerName,
[Parameter(Mandatory)]
[string]$IntegratedSecurity,
[Parameter(Mandatory)]
[string]$UserName,
[Parameter(Mandatory)]
[string]$Password
)
$ErrorActionPreference = 'Stop'
try {
$connectionString = 'Server={0};Integrated Security={1};User ID={2};Password={3}' -f $ServerName,$IntegratedSecurity,$UserName,$Password
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection $connectionString
$sqlConnection.Open()
Write-Host -Object "Connection to SQL Express was successful."
2020-03-18 00:16:00 +07:00
return $sqlConnection.ServerVersion
2020-03-20 00:28:25 +07:00
2020-03-17 23:22:20 +07:00
} catch {
Write-Host -Object "Connection to SQL Express cannot be established."
exit 1
2020-03-20 00:28:25 +07:00
2020-03-17 23:22:20 +07:00
} finally {
## Close the connection when we're done
$sqlConnection.Close()
}
2020-03-12 21:22:54 +07:00
}
2020-03-19 01:36:41 +07:00
$instanceName = "$env:computername\$sqlInstance"
$version = Test-SqlConnection -ServerName $instanceName -IntegratedSecurity "false" -UserName $sqlUser -Password $sqlPassword
2020-03-18 00:16:00 +07:00
# Adding description of the software to Markdown
2020-04-09 10:16:26 +02:00
$SoftwareName = "Microsoft SQL Express"
2020-03-18 00:16:00 +07:00
$Description = @"
_Version:_ $version<br/>
2020-03-19 01:36:41 +07:00
_InstanceName:_ $sqlInstance<br/>
_Username:_ $sqlUser<br/>
_Password:_ $sqlPassword<br/>
2020-03-18 00:16:00 +07:00
_Default Path:_ C:\Program Files (x86)\Microsoft SQL Server
"@
Add-SoftwareDetailsToMarkdown -SoftwareName $SoftwareName -DescriptionMarkdown $Description