Skip to content

Commit 9eaf7c9

Browse files
author
sql-williamd
committed
syntax/style issue fixes
1 parent 4fdd85b commit 9eaf7c9

1 file changed

Lines changed: 39 additions & 30 deletions

File tree

Install.ps1

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Will install the centralized version on instance SQL2012 database named db3 and
7777
param (
7878
[parameter(Mandatory = $true)]
7979
[string]$SqlInstance,
80-
[Alias("SqlCredential")]
80+
[Alias("SqlCredential")]
8181
[PSCredential]$Credential,
8282
[parameter(Mandatory = $true)]
8383
[string]$Database,
@@ -203,35 +203,35 @@ PROCESS {
203203
$instance = New-Object Microsoft.SqlServer.Management.Smo.Server $SqlInstance
204204

205205
try {
206-
if ($Credential.username -ne $null) {
207-
$username = ($Credential.username).TrimStart("\")
208-
209-
if ($username -like "*\*") {
210-
$username = $username.Split("\")[1]
211-
$authtype = "Windows Authentication with Credential"
212-
$instance.ConnectionContext.LoginSecure = $true
213-
$instance.ConnectionContext.ConnectAsUser = $true
214-
$instance.ConnectionContext.ConnectAsUserName = $username
215-
$instance.ConnectionContext.ConnectAsUserPassword = ($Credential).GetNetworkCredential().Password
216-
}
217-
else {
218-
$authtype = "SQL Authentication"
219-
$instance.ConnectionContext.LoginSecure = $false
220-
$instance.ConnectionContext.set_Login($username)
221-
$instance.ConnectionContext.set_SecurePassword($Credential.Password)
222-
}
223-
}
206+
if ($null -ne $Credential.username) {
207+
$username = ($Credential.username).TrimStart("\")
208+
209+
if ($username -like "*\*") {
210+
$username = $username.Split("\")[1]
211+
$authtype = "Windows Authentication with Credential"
212+
$instance.ConnectionContext.LoginSecure = $true
213+
$instance.ConnectionContext.ConnectAsUser = $true
214+
$instance.ConnectionContext.ConnectAsUserName = $username
215+
$instance.ConnectionContext.ConnectAsUserPassword = ($Credential).GetNetworkCredential().Password
216+
}
217+
else {
218+
$authtype = "SQL Authentication"
219+
$instance.ConnectionContext.LoginSecure = $false
220+
$instance.ConnectionContext.set_Login($username)
221+
$instance.ConnectionContext.set_SecurePassword($Credential.Password)
222+
}
223+
}
224224

225225
Write-Verbose "Connecting via SMO to $SqlInstance using $authtype"
226-
$instance.ConnectionContext.Connect()
227-
}
228-
catch {
229-
$message = $_.Exception.InnerException.InnerException
230-
$message = $message.ToString()
231-
$message = ($message -Split '-->')[0]
232-
$message = ($message -Split 'at System.Data.SqlClient')[0]
233-
$message = ($message -Split 'at System.Data.ProviderBase')[0]
234-
Invoke-Catch -Message "Failed to connect to $SqlInstance`: $message "
226+
$instance.ConnectionContext.Connect()
227+
}
228+
catch {
229+
$message = $_.Exception.InnerException.InnerException
230+
$message = $message.ToString()
231+
$message = ($message -Split '-->')[0]
232+
$message = ($message -Split 'at System.Data.SqlClient')[0]
233+
$message = ($message -Split 'at System.Data.ProviderBase')[0]
234+
Invoke-Catch -Message "Failed to connect to $SqlInstance`: $message "
235235
}
236236
}
237237
catch {
@@ -257,14 +257,23 @@ PROCESS {
257257

258258
Write-Verbose "Checking the Compatibility Level of Database $Database on $SqlInstance"
259259
# We only support between SQL Server 2008 (version100) and SQL Server 2014 (version120)
260-
$CompLevel=$instance.databases|where-Object Name -eq $Database|select CompatibilityLevel
260+
$CompLevel = $instance.databases | Where-Object Name -eq $Database | Select-Object CompatibilityLevel
261261
if ($CompLevel.CompatibilityLevel -replace "Version" -lt 100 -or $CompLevel.CompatibilityLevel -replace "Version" -gt 120 ) {
262-
Invoke-Catch -Message "OQS is only supported between SQL Server 2008 (version100) to SQL Server 2014 (version120). Your database compatibility level is $($CompLevel.CompatibilityLevel). Installation cancelled."
262+
Invoke-Catch -Message "OQS is only supported between SQL Server 2008 (version100) to SQL Server 2014 (version120). Your database compatibility level is $($CompLevel.CompatibilityLevel). Installation cancelled."
263263
}
264264
Write-Verbose "Database compatibility Check passed - Compatibility is $($CompLevel.CompatibilityLevel)"
265265

266266
# If we are installing Service Broker for scheduling, we need to do housekeeping for the certificate
267267
if ($InstallationType -eq "Service Broker") {
268+
269+
Write-Verbose "Checking if Database $Database has Service Broker activated on $SqlInstance"
270+
if ($pscmdlet.ShouldProcess("$SqlInstance", "Checking if service broker is enabled in $database")) {
271+
if (-not ($instance.Databases | Where-Object Name -eq $Database) -and ($BrokerEnabled -eq $True)) {
272+
Invoke-Catch -Message "Service Broker is not enabled in [$Database] on instance $SqlInstance. This is a blocking operation, please enable service broker and re-run this installer."
273+
}
274+
}
275+
Write-Verbose "Service Broker is enabled in $Database on $SqlInstance"
276+
268277
Write-Verbose "Checking Certificate Backup Path $CertificateBackupPath exists"
269278
#Does the path specified even exist and is it accessible?
270279
if (-not (Test-Path $CertificateBackupPath -PathType Container)) {

0 commit comments

Comments
 (0)