@@ -196,7 +196,6 @@ function New-DbaConnectionString {
196
196
[string ]$ClientName = " custom connection" ,
197
197
[int ]$ConnectTimeout ,
198
198
[string ]$Database ,
199
- [ValidateSet (' Mandatory' , ' Optional' , ' Strict' , ' True' , ' False' )]
200
199
[switch ]$EncryptConnection = (Get-DbatoolsConfigValue - FullName ' sql.connection.encrypt' ),
201
200
[string ]$FailoverPartner ,
202
201
[switch ]$IsActiveDirectoryUniversalAuth ,
@@ -271,9 +270,6 @@ function New-DbaConnectionString {
271
270
if (Test-Bound -Not - ParameterName ' ConnectTimeout' ) {
272
271
$ConnectTimeout = ([Dataplat.Dbatools.Connection.ConnectionHost ]::SqlConnectionTimeout)
273
272
}
274
- if (Test-Bound -Not - ParameterName ' EncryptConnection' ) {
275
- $EncryptConnection = (Get-DbatoolsConfigValue - FullName ' sql.connection.encrypt' )
276
- }
277
273
if (Test-Bound -Not - ParameterName ' NetworkProtocol' ) {
278
274
$np = (Get-DbatoolsConfigValue - FullName ' sql.connection.protocol' )
279
275
if ($np ) {
@@ -320,7 +316,8 @@ function New-DbaConnectionString {
320
316
if ($Database ) { $connStringBuilder [' Initial Catalog' ] = $Database }
321
317
# https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlconnectionstringbuilder.encrypt?view=sqlclient-dotnet-standard-5.0
322
318
if ($instance -notmatch " localdb" ) {
323
- if ($EncryptConnection ) { $connStringBuilder [' Encrypt' ] = $EncryptConnection }
319
+ if ($EncryptConnection ) { $connStringBuilder [' Encrypt' ] = ' Mandatory' }
320
+ if (-not $EncryptConnection -and (Test-Bound - ParameterName ' EncryptConnection' )) { $connStringBuilder [' Encrypt' ] = ' False' }
324
321
} else {
325
322
Write-Message - Level Verbose - Message " localdb detected, skipping unsupported keyword 'Encryption'"
326
323
}
0 commit comments