Skip to content

Commit 99df60d

Browse files
committed
added -TrustServerCertificate to first SQL Server connection
1 parent a16745d commit 99df60d

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

CI/Azure-DevOps/CreateSQLVM_azcli.ps1

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
<# USAGE: ./CreateSQLVM.ps1 -Location "East US 2" -Size "Standard_D2as_v4" -ResourceGroupName "myTestResourceGroup" -VMAdminName "azureAdminName" -VMAdminPwd "aoeihag;ladjfalkj23" -SQLVersionEdition "2017" -SQLPort "41433" -SQLUserName "tSQLt_sa" -SQLPwd "aoeihag;ladjfalkj46" -BuildId "001" #>
1+
<# USAGE:
2+
3+
az login
4+
az account set --name "tSQLt CI Subscription"
5+
6+
./CreateSQLVM_azcli.ps1 -Location "East US 2" -Size "Standard_D2as_v4" -ResourceGroupName "myTestResourceGroup" -VMAdminName "azureadminname" -VMAdminPwd "aoeihag;ladjfalkj23" -SQLVersionEdition "2017" -SQLPort "41433" -SQLUserName "tSQLt_sa" -SQLPwd "aoeihag;ladjfalkj46" -BuildId "001" -VmPriority "Spot"
7+
#>
28
Param(
39
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $Location,
410
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $Size,
@@ -99,21 +105,30 @@ Log-Output "FQDN: ", $FQDN;
99105
Log-Output "DONE: Creating PIP $PipName";
100106

101107
Log-Output "START: Creating NSG and Rules $NsgName";
108+
Log-Output "START: Creating NSG and Rules $NsgName --> nsg create";
102109
$output = az network nsg create --name $NsgName --resource-group $ResourceGroupName --location $Location | ConvertFrom-Json;
103110
if (!$output) {
104111
Write-Error "Error creating NIC";
105112
return
106113
}
114+
Log-Output "START: Creating NSG and Rules $NsgName --> nsg rule create --name `"RDPRule`"";
115+
$DestPort = 3389;
116+
Log-Output "<-><-><-><-><-><-><-><-><-><-><-><-><-><->";
117+
Log-Output "ResourceGroupName: ", $ResourceGroupName;
118+
Log-Output "NsgName: ", $NsgName;
119+
Log-Output "DestPort: ", $DestPort;
120+
Log-Output "<-><-><-><-><-><-><-><-><-><-><-><-><-><->";
107121
$output = az network nsg rule create --name "RDPRule" --nsg-name $NsgName --priority 1000 --resource-group $ResourceGroupName --access Allow `
108-
--destination-address-prefixes * --destination-port-ranges 3389 --direction Inbound --protocol Tcp --source-address-prefixes * `
109-
--source-port-ranges * | ConvertFrom-Json;
122+
--destination-address-prefixes '*' --destination-port-ranges $DestPort --direction Inbound --protocol Tcp --source-address-prefixes '*' `
123+
--source-port-ranges '*' | ConvertFrom-Json;
110124
if (!$output) {
111125
Write-Error "Error creating NIC RDPRule";
112126
return
113127
}
128+
Log-Output "START: Creating NSG and Rules $NsgName --> nsg rule create --name `"MSSQLRule`"";
114129
$output = az network nsg rule create --name "MSSQLRule" --nsg-name $NsgName --priority 1001 --resource-group $ResourceGroupName --access Allow `
115-
--destination-address-prefixes * --destination-port-ranges $SQLPort --direction Inbound --protocol Tcp --source-address-prefixes * `
116-
--source-port-ranges * | ConvertFrom-Json;
130+
--destination-address-prefixes '*' --destination-port-ranges $SQLPort --direction Inbound --protocol Tcp --source-address-prefixes '*' `
131+
--source-port-ranges '*' | ConvertFrom-Json;
117132
if (!$output) {
118133
Write-Error "Error creating NIC MSSQLRule";
119134
return
@@ -162,8 +177,16 @@ if (!$output) {
162177
$SQLVM|Out-String|Log-Output;
163178
Log-Output 'DONE: Applying SqlVM Config'
164179

180+
# Log-Output 'START: Getting SQL Server Certificate'
181+
# & openssl s_client -connect "$FQDN`:$SQLPort" -showcerts </dev/null 2>/dev/null | openssl x509 -outform PEM > "Connection_Certificate_$VMName.pem"
182+
# $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("Connection_Certificate_$VMName.pem")
183+
# $store = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::TrustedPeople, 'LocalMachine')
184+
# $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
185+
# $store.Add($cert)
186+
# $store.Close()
187+
165188
Log-Output 'START: Prep SQL Server for tSQLt Build'
166-
$DS = Invoke-Sqlcmd -InputFile "$dir/GetSQLServerVersion.sql" -ServerInstance "$FQDN,$SQLPort" -Username "$SQLUserName" -Password "$SQLPwd" -As DataSet
189+
$DS = Invoke-Sqlcmd -InputFile "$dir/GetSQLServerVersion.sql" -ServerInstance "$FQDN,$SQLPort" -Username "$SQLUserName" -Password "$SQLPwd" -As DataSet -TrustServerCertificate
167190
$DS.Tables[0].Rows | %{ Log-Output "{ $($_['LoginName']), $($_['TimeStamp']), $($_['VersionDetail']), $($_['ProductVersion']), $($_['ProductLevel']), $($_['SqlVersion']), $($_['ServerCollation']) }" }
168191

169192
$ActualSQLVersion = $DS.Tables[0].Rows[0]['SqlVersion'];

0 commit comments

Comments
 (0)