diff --git a/CHANGELOG.md b/CHANGELOG.md index 999528920..93d7febca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,7 +51,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This parameter can only be used together with the module _SqlServer_ installed (tested v21.0.17099). The parameter will be ignored if SQLPS module will be used. ->>>>>>> upstream/main ## [16.2.0] - 2023-04-10 diff --git a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 index ada8c0153..921b0b9f5 100644 --- a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 +++ b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 @@ -45,9 +45,6 @@ function Get-TargetResource # Connect to the instance $serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop' - # Get SQL module name - $sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name - # Define current version for check compatibility $sqlMajorVersion = $serverObject.Version.Major @@ -96,10 +93,16 @@ function Get-TargetResource $alwaysOnAvailabilityGroupResource.Add('BasicAvailabilityGroup', $availabilityGroup.BasicAvailabilityGroup) $alwaysOnAvailabilityGroupResource.Add('DatabaseHealthTrigger', $availabilityGroup.DatabaseHealthTrigger) $alwaysOnAvailabilityGroupResource.Add('DtcSupportEnabled', $availabilityGroup.DtcSupportEnabled) - if ( $sqlModuleName -eq 'SQLServer' ) + # Microsoft.SqlServer.Management.Smo.Server from Connect-SQL supports the SeedingMode for SQL 2016 and higher, but New-SqlAvailabilityReplica may not. + # Will setting SeedingMode as $null to match ability of Microsoft.SqlServer.Management.Smo.Server and New-SqlAvailabilityReplica + if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) { $alwaysOnAvailabilityGroupResource.Add('SeedingMode', $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode) } + else + { + $alwaysOnAvailabilityGroupResource.Add('SeedingMode', $null) + } } } @@ -262,9 +265,6 @@ function Set-TargetResource # Connect to the instance $serverObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName -ErrorAction 'Stop' - # Get SQL module name - $sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name - # Determine if HADR is enabled on the instance. If not, throw an error if ( -not $serverObject.IsHadrEnabled ) { @@ -356,7 +356,7 @@ function Set-TargetResource $newReplicaParams.Add('ConnectionModeInSecondaryRole', $ConnectionModeInSecondaryRole) } - if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $sqlMajorVersion -ge 13 ) -and (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) { $newReplicaParams.Add('SeedingMode', $SeedingMode) } @@ -521,10 +521,13 @@ function Set-TargetResource Update-AvailabilityGroup -AvailabilityGroup $availabilityGroup } - if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode ) ) { - $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode = $SeedingMode - Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName] + if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) + { + $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName].SeedingMode = $SeedingMode + Update-AvailabilityGroupReplica -AvailabilityGroupReplica $availabilityGroup.AvailabilityReplicas[$serverObject.DomainInstanceName] + } } } } @@ -710,9 +713,6 @@ function Test-TargetResource # Define current version for check compatibility $sqlMajorVersion = $getTargetResourceResult.Version - # Get SQL module name - $sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name - switch ($Ensure) { 'Absent' @@ -747,12 +747,13 @@ function Test-TargetResource <# Add properties compatible with SQL Server 2016 or later versions DtcSupportEnabled is enabled at the creation of the Availability Group only, hence it will not be checked in this block + SeedingMode should be checked only in case if New-SqlAvailabilityReplica support the SeedingMode parameter #> if ( $sqlMajorVersion -ge 13 ) { $parametersToCheck += 'BasicAvailabilityGroup' $parametersToCheck += 'DatabaseHealthTrigger' - if ( $sqlModuleName -eq 'SQLServer' ) + if ( $getTargetResourceResult.SeedingMode ) { $parametersToCheck += 'SeedingMode' } diff --git a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 index 97f479ad7..908e31ca6 100644 --- a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 +++ b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 @@ -56,9 +56,6 @@ function Get-TargetResource # Define current version for check compatibility $sqlMajorVersion = $serverObject.Version.Major - # Get SQL module name - $sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name - # Is this node actively hosting the SQL instance? $isActiveNode = Test-ActiveNode -ServerObject $serverObject @@ -89,7 +86,7 @@ function Get-TargetResource EndpointHostName = $serverObject.NetName } - if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $sqlMajorVersion -ge 13 ) ) { $alwaysOnAvailabilityGroupReplicaResource.Add('SeedingMode', '') } @@ -115,9 +112,16 @@ function Get-TargetResource $alwaysOnAvailabilityGroupReplicaResource.ReadOnlyRoutingConnectionUrl = $availabilityGroupReplica.ReadOnlyRoutingConnectionUrl $alwaysOnAvailabilityGroupReplicaResource.ReadOnlyRoutingList = $availabilityGroupReplica.ReadOnlyRoutingList - if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( $sqlMajorVersion -ge 13 ) { - $alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $availabilityGroupReplica.SeedingMode + if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) + { + $alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $availabilityGroupReplica.SeedingMode + } + else + { + $alwaysOnAvailabilityGroupReplicaResource.'SeedingMode' = $null + } } } } @@ -272,9 +276,6 @@ function Set-TargetResource # Define current version for check compatibility $sqlMajorVersion = $serverObject.Version.Major - # Get SQL module name - $sqlModuleName = (Get-Module -FullyQualifiedName (Get-SqlDscPreferredModule -ErrorAction 'Stop') -ListAvailable).Name - # Determine if HADR is enabled on the instance. If not, throw an error if ( -not $serverObject.IsHadrEnabled ) { @@ -428,10 +429,13 @@ function Set-TargetResource $availabilityGroupReplicaUpdatesRequired = $true } - if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroupReplica.SeedingMode ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $submittedParameters -contains 'SeedingMode' ) -and ( $sqlMajorVersion -ge 13 ) -and ( $SeedingMode -ne $availabilityGroupReplica.SeedingMode ) ) { - $availabilityGroupReplica.SeedingMode = $SeedingMode - $availabilityGroupReplicaUpdatesRequired = $true + if ((Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode')) + { + $availabilityGroupReplica.SeedingMode = $SeedingMode + $availabilityGroupReplicaUpdatesRequired = $true + } } if ( $availabilityGroupReplicaUpdatesRequired ) @@ -495,7 +499,7 @@ function Set-TargetResource $newAvailabilityGroupReplicaParams.Add('ReadOnlyRoutingList', $ReadOnlyRoutingList) } - if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $sqlMajorVersion -ge 13 ) -and (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) { $newAvailabilityGroupReplicaParams.Add('SeedingMode', $SeedingMode) }