From de6c1743c863637c10c68b661909f92dee019c89 Mon Sep 17 00:00:00 2001 From: Sydorenko Andrii <50662809+Sidoran@users.noreply.github.com> Date: Mon, 24 Apr 2023 12:32:55 +0200 Subject: [PATCH 1/5] remove merge artifact --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) 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 From acba671dbfcbdf1fab1de8b55f4e0a178435ffaf Mon Sep 17 00:00:00 2001 From: Sydorenko Andrii <50662809+Sidoran@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:28:17 +0200 Subject: [PATCH 2/5] SeedingMode fixes --- source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 | 31 ++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 index ada8c0153..b8ba5bc1e 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 ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) { $parametersToCheck += 'SeedingMode' } From c4583ea0853144f34b837c9ba9d54988fbcf3f46 Mon Sep 17 00:00:00 2001 From: Sydorenko Andrii <50662809+Sidoran@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:49:43 +0200 Subject: [PATCH 3/5] update test function --- source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 index b8ba5bc1e..921b0b9f5 100644 --- a/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 +++ b/source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1 @@ -753,7 +753,7 @@ function Test-TargetResource { $parametersToCheck += 'BasicAvailabilityGroup' $parametersToCheck += 'DatabaseHealthTrigger' - if ( (Get-Command -Name 'New-SqlAvailabilityReplica').Parameters.ContainsKey('SeedingMode') ) + if ( $getTargetResourceResult.SeedingMode ) { $parametersToCheck += 'SeedingMode' } From 1aec2fdd1556862c046fa47b2cfb9bc7b29b5173 Mon Sep 17 00:00:00 2001 From: Sydorenko Andrii <50662809+Sidoran@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:52:18 +0200 Subject: [PATCH 4/5] update SQLAGreplica --- .../DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 index 97f479ad7..c541a4866 100644 --- a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 +++ b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 @@ -89,7 +89,7 @@ function Get-TargetResource EndpointHostName = $serverObject.NetName } - if ( ( $sqlMajorVersion -ge 13 ) -and ( $sqlModuleName -eq 'SQLServer' ) ) + if ( ( $sqlMajorVersion -ge 13 ) ) { $alwaysOnAvailabilityGroupReplicaResource.Add('SeedingMode', '') } @@ -115,9 +115,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 + } } } } @@ -428,10 +435,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 +505,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) } From dfa16e8580d66eaa03a3f05016def32598b9c46f Mon Sep 17 00:00:00 2001 From: Sydorenko Andrii <50662809+Sidoran@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:02:40 +0200 Subject: [PATCH 5/5] remove sqlmodulename --- source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 b/source/DSCResources/DSC_SqlAGReplica/DSC_SqlAGReplica.psm1 index c541a4866..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 @@ -279,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 ) {