From 24a49ab07296c0625c70ca097d231e9b62ef3d87 Mon Sep 17 00:00:00 2001 From: Andreas Jordan <66946165+andreasjordan@users.noreply.github.com> Date: Thu, 11 Apr 2024 09:34:21 +0200 Subject: [PATCH] Copy-DbaCredential - Force DAC as it is needed for decryption (#9306) --- public/Copy-DbaCredential.ps1 | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/public/Copy-DbaCredential.ps1 b/public/Copy-DbaCredential.ps1 index 86c50b0865..ce59a19ae3 100644 --- a/public/Copy-DbaCredential.ps1 +++ b/public/Copy-DbaCredential.ps1 @@ -9,7 +9,9 @@ function Copy-DbaCredential { Credit: https://blog.netspi.com/decrypting-mssql-database-link-server-passwords/ .PARAMETER Source - Source SQL Server. You must have sysadmin access and server version must be SQL Server version 2000 or higher. + Source SQL Server. You must have sysadmin access and server version must be SQL Server version 2005 or higher. + + You must be able to open a dedicated admin connection (DAC) to the source SQL Server. .PARAMETER SourceSqlCredential Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). @@ -19,7 +21,7 @@ function Copy-DbaCredential { For MFA support, please use Connect-DbaInstance. .PARAMETER Destination - Destination SQL Server. You must have sysadmin access and the server must be SQL Server 2000 or higher. + Destination SQL Server. You must have sysadmin access and the server must be SQL Server 2005 or higher. .PARAMETER DestinationSqlCredential Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential). @@ -123,13 +125,8 @@ function Copy-DbaCredential { if ($Force) { $ConfirmPreference = 'none' } try { - try { - Write-Message -Level Verbose -Message "We will try to use a dedicated admin connection." - $sourceServer = Connect-DbaInstance -SqlInstance $Source -SqlCredential $SourceSqlCredential -MinimumVersion 9 -DedicatedAdminConnection -WarningAction SilentlyContinue - } catch { - Write-Message -Level Verbose -Message "Failed to open a dedicated admin connection. We will fallback to a normal connection." - $sourceServer = Connect-DbaInstance -SqlInstance $Source -SqlCredential $SourceSqlCredential -MinimumVersion 9 - } + Write-Message -Level Verbose -Message "We will try to open a dedicated admin connection." + $sourceServer = Connect-DbaInstance -SqlInstance $Source -SqlCredential $SourceSqlCredential -MinimumVersion 9 -DedicatedAdminConnection -WarningAction SilentlyContinue } catch { Stop-Function -Message "Failure" -Category ConnectionError -ErrorRecord $_ -Target $Source return @@ -234,7 +231,7 @@ function Copy-DbaCredential { } } end { - # Disconnect is important because it might be a DAC + # Disconnect is important because it is a DAC # Disconnect in case of WhatIf, as we opened the connection $null = $sourceServer | Disconnect-DbaInstance -WhatIf:$false }