@@ -287,7 +287,8 @@ function Set-TargetResource
287287 Install-RemoteDistributor `
288288 - ReplicationServer $localReplicationServer `
289289 - RemoteDistributor $RemoteDistributor `
290- - AdminLinkCredentials $AdminLinkCredentials
290+ - AdminLinkCredentials $AdminLinkCredentials `
291+ - InstanceName $InstanceName
291292 }
292293 }
293294 else # 'Absent'
@@ -437,7 +438,7 @@ function New-ServerConnection
437438 $SqlServerName
438439 )
439440
440- if ($SqlMajorVersion -eq 16 )
441+ if ($SqlMajorVersion -in @ ( 16 , 17 ) )
441442 {
442443 <#
443444 For SQL Server 2022 the object must be created with New-Object and
@@ -598,6 +599,9 @@ function New-DistributionPublisher
598599 . PARAMETER AdminLinkCredentials
599600 AdminLink password to be used when setting up publisher distributor
600601 relationship.
602+
603+ . PARAMETER InstanceName
604+ SQL Server instance name where replication distribution will be configured.
601605#>
602606function Install-RemoteDistributor
603607{
@@ -614,22 +618,50 @@ function Install-RemoteDistributor
614618
615619 [Parameter (Mandatory = $true )]
616620 [System.Management.Automation.PSCredential ]
617- $AdminLinkCredentials
621+ $AdminLinkCredentials ,
622+
623+ [Parameter (Mandatory = $true )]
624+ [System.String ]
625+ $InstanceName
618626 )
619627
620628 Write-Verbose - Message (
621629 $script :localizedData.InstallRemoteDistributor -f $RemoteDistributor
622630 )
623631
624- try
632+ $serverObject = Connect-SqlDscDatabaseEngine - InstanceName $InstanceName - ErrorAction ' Stop'
633+
634+ $sqlMajorVersion = $serverObject.VersionMajor
635+
636+ if ($sqlMajorVersion -eq 17 )
625637 {
626- $ReplicationServer.InstallDistributor ($RemoteDistributor , $AdminLinkCredentials.Password )
638+ $clearTextPassword = $AdminLinkCredentials.GetNetworkCredential ().Password
639+
640+ <#
641+ Need to execute stored procedure sp_adddistributor for SQL Server 2025.
642+ Workaround for issue: https://github.com/dsccommunity/SqlServerDsc/pull/2435#issuecomment-3796616952
643+
644+ TODO: Should support encrypted connection in the future, then we could
645+ probably go back to using InstallDistributor(), another option is
646+ to move to stored procedures for all of the Replication logic.
647+ #>
648+ $query = " EXECUTE sys.sp_adddistributor @distributor = N'$RemoteDistributor ', @password = N'$clearTextPassword ', @encrypt_distributor_connection = 'optional', @trust_distributor_certificate = 'yes';"
649+
650+ # TODO: This need to pass a credential in the future, now connects using the one resource is run as.
651+ Invoke-SqlDscQuery - ServerObject $serverObject - DatabaseName ' master' - Query $query - RedactText $clearTextPassword - Force - ErrorAction ' Stop'
627652 }
628- catch
653+ else
629654 {
630- $errorMessage = $script :localizedData.FailedInFunction -f ' Install-RemoteDistributor'
655+ try
656+ {
657+ $ReplicationServer.InstallDistributor ($RemoteDistributor , $AdminLinkCredentials.Password )
658+ }
659+ catch
660+ {
661+ $errorMessage = $script :localizedData.FailedInFunction -f ' Install-RemoteDistributor'
631662
632- New-InvalidOperationException - Message $errorMessage - ErrorRecord $_
663+ New-InvalidOperationException - Message $errorMessage - ErrorRecord $_
664+ }
633665 }
634666}
635667
0 commit comments