diff --git a/.github/workflows/gallery.yml b/.github/workflows/gallery.yml index 5f7876283e..196c493e6a 100644 --- a/.github/workflows/gallery.yml +++ b/.github/workflows/gallery.yml @@ -33,7 +33,7 @@ jobs: - name: Set encryption values run: | Import-Module dbatools - Set-DbatoolsInsecureConnection -Register + Set-DbatoolsInsecureConnection Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Write-Warning - name: Setup docker images diff --git a/public/Set-DbatoolsInsecureConnection.ps1 b/public/Set-DbatoolsInsecureConnection.ps1 index 5a38d87a46..56ee4df0e8 100644 --- a/public/Set-DbatoolsInsecureConnection.ps1 +++ b/public/Set-DbatoolsInsecureConnection.ps1 @@ -12,14 +12,17 @@ function Set-DbatoolsInsecureConnection { You can read more here: https://dbatools.io/newdefaults - .PARAMETER Register - Registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell. + .PARAMETER SessionOnly + Does not persist across sessions so the default will return if you close and reopen PowerShell. .PARAMETER Scope The configuration scope it should be registered under. Defaults to UserDefault. Configuration scopes are the default locations configurations are being stored at. + .PARAMETER Register + Deprecated. + .LINK https://dbatools.io/Set-DbatoolsInsecureConnection https://blog.netnerds.net/2023/03/new-defaults-for-sql-server-connections-encryption-trust-certificate/ @@ -30,24 +33,28 @@ function Set-DbatoolsInsecureConnection { Sets the default connection settings to trust all server certificates and not require encrypted connections. .EXAMPLE - PS C:\> Set-DbatoolsInsecureConnection -Register + PS C:\> Set-DbatoolsInsecureConnection -SessionOnly Sets the default connection settings to trust all server certificates and not require encrypted connections. - Registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell. + Does not persist across sessions so the default will return if you close and reopen PowerShell. #> [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [CmdletBinding()] param ( - [switch]$Register, - [Dataplat.Dbatools.Configuration.ConfigScope]$Scope = [Dataplat.Dbatools.Configuration.ConfigScope]::UserDefault + [switch]$SessionOnly, + [Dataplat.Dbatools.Configuration.ConfigScope]$Scope = [Dataplat.Dbatools.Configuration.ConfigScope]::UserDefault, + [switch]$Register ) process { + if ($Register) { + Write-Message -Level Warning -Message "The Register parameter is deprecated and will be removed in a future release." + } # Set these defaults for all future sessions on this machine Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Passthru Set-DbatoolsConfig -FullName sql.connection.encrypt -Value $false -Passthru - if ($Register) { + if (-not $SessionOnly) { Register-DbatoolsConfig -FullName sql.connection.trustcert -Scope $Scope Register-DbatoolsConfig -FullName sql.connection.encrypt -Scope $Scope } diff --git a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 index ffa0d2042c..fec1dbcc5d 100644 --- a/tests/Set-DbatoolsInsecureConnection.Tests.ps1 +++ b/tests/Set-DbatoolsInsecureConnection.Tests.ps1 @@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } - [object[]]$knownParameters = 'Register', 'Scope' + [object[]]$knownParameters = 'Register', 'SessionOnly', 'Scope' $knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters It "Should only contain our specific parameters" { (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 @@ -32,11 +32,5 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { # sql.connection.encrypt is a string because it needs to be mandatory, optional, true or false Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Should -Be 'False' } - - It "registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell" { - $null = Set-DbatoolsInsecureConnection -Register - Get-DbatoolsConfigValue -FullName sql.connection.trustcert | Should -BeTrue - Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Should -Be 'False' - } } } \ No newline at end of file