Skip to content

Commit

Permalink
Encryption Check - Add support for string settings
Browse files Browse the repository at this point in the history
Whatever happened changed the settings and I got that C O M P U T E R  M E S S A G E again which I shouldn't have.
  • Loading branch information
potatoqualitee committed Nov 5, 2023
1 parent 714219c commit 646add6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 2 additions & 1 deletion dbatools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,8 @@ $script:connectionhash = @{ }
if (Get-DbatoolsConfigValue -FullName Import.EncryptionMessageCheck) {
$trustcert = Get-DbatoolsConfigValue -FullName sql.connection.trustcert
$encrypt = Get-DbatoolsConfigValue -FullName sql.connection.encrypt
if (-not $trustcert -or $encrypt) {
# support old settings as well for those whose settings are stuck on string
if (-not $trustcert -or $encrypt -in @("Mandatory", "$true", $true)) {
# keep it write-host for psv3
Write-Message -Level Output -Message '
/ / / /
Expand Down
11 changes: 10 additions & 1 deletion private/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,16 @@ if (-not $script:dbatools_ImportFromRegistryDone) {
foreach ($value in $config_hash.Values) {
try {
if (-not $value.KeepPersisted) {
Set-DbatoolsConfig -FullName $value.FullName -Value $value.Value -EnableException
if ($value.FullName -eq "sql.connection.encrypt") {
# Conversion from older string settings. needs actual bool.
if ($value.Value -eq $false) {
Set-DbatoolsConfig -FullName $value.FullName -Value $false -EnableException
} else {
Set-DbatoolsConfig -FullName $value.FullName -Value $true -EnableException
}
} else {
Set-DbatoolsConfig -FullName $value.FullName -Value $value.Value -EnableException
}
} else {
Set-DbatoolsConfig -FullName $value.FullName -PersistedValue $value.Value -PersistedType $value.Type -EnableException
}
Expand Down
8 changes: 6 additions & 2 deletions public/Get-DbatoolsConfigValue.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ function Get-DbatoolsConfigValue {

$temp = $null
$temp = [Dataplat.Dbatools.Configuration.ConfigurationHost]::Configurations[$FullName].Value
if ($temp -eq $null) { $temp = $Fallback }
if ($null -eq $temp) { $temp = $Fallback }

if ($NotNull -and ($temp -eq $null)) {
# Prevent some potential [switch] parse issues
if ($temp -eq "Mandatory") { $temp = $true }
if ($temp -eq "Optional") { $temp = $false }

if ($NotNull -and ($null -eq $temp)) {
Stop-Function -Message "No Configuration Value available for $Name" -EnableException $true -Category InvalidData -Target $FullName
} else {
return $temp
Expand Down

0 comments on commit 646add6

Please sign in to comment.