Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee committed May 18, 2024
2 parents 5970711 + 22c7bc9 commit 6c7cb4b
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gallery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install and cache PowerShell modules
uses: potatoqualitee/[email protected]
with:
modules-to-cache: dbatools.library:2024.3.9
modules-to-cache: dbatools.library:2024.4.12

- name: Download dbatools from Gallery
run: |
Expand Down
7 changes: 6 additions & 1 deletion bin/dbatools-buildref-index.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"LastUpdated": "2024-04-11T00:00:00",
"LastUpdated": "2024-05-16T00:00:00",
"Data": [
{
"Version": "8.0.47",
Expand Down Expand Up @@ -4683,6 +4683,11 @@
{
"Version": "16.0.4120",
"KBList": "5036343"
},
{
"CU": "CU13",
"Version": "16.0.4125",
"KBList": "5036432"
}
]
}
Binary file modified bin/dbatools-index.json
Binary file not shown.
6 changes: 4 additions & 2 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2012 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 1, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1380,19 +1380,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 52) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.creation_time AS [Creation Time]
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2014 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 1, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1406,20 +1406,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 53) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
CONVERT(nvarchar(25), qs.last_execution_time, 20) AS [Last Execution Time],
CONVERT(nvarchar(25), qs.creation_time, 20) AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2016 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 1, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1470,20 +1470,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 54) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
FORMAT(qs.last_execution_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Last Execution Time],
FORMAT(qs.creation_time, 'yyyy-MM-dd HH:mm:ss', 'en-US') AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2016 SP2 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 1, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1485,20 +1485,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 57) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
CONVERT(nvarchar(25), qs.last_execution_time, 20) AS [Last Execution Time],
CONVERT(nvarchar(25), qs.creation_time, 20) AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2017 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 1, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1521,20 +1521,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 58) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
CONVERT(nvarchar(25), qs.last_execution_time, 20) AS [Last Execution Time],
CONVERT(nvarchar(25), qs.creation_time, 20) AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2019 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 11, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1596,20 +1596,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 60) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
CONVERT(nvarchar(25), qs.last_execution_time, 20) AS [Last Execution Time],
CONVERT(nvarchar(25), qs.creation_time, 20) AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
9 changes: 5 additions & 4 deletions bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

-- SQL Server 2022 Diagnostic Information Queries
-- Glenn Berry
-- Last Modified: April 9, 2024
-- Last Modified: May 2, 2024
-- https://glennsqlperformance.com/
-- https://sqlserverperformance.wordpress.com/
-- YouTube: https://bit.ly/2PkoAM1
Expand Down Expand Up @@ -1666,20 +1666,21 @@ ON vfs.[file_id]= df.[file_id] OPTION (RECOMPILE);

-- Get most frequently executed queries for this database (Query 62) (Query Execution Counts)
SELECT TOP(50) LEFT(t.[text], 50) AS [Short Query Text], qs.execution_count AS [Execution Count],
ISNULL(qs.execution_count/DATEDIFF(Minute, qs.creation_time, GETDATE()), 0) AS [Calls/Minute],
qs.total_logical_reads AS [Total Logical Reads],
qs.total_logical_reads/qs.execution_count AS [Avg Logical Reads],
qs.total_worker_time AS [Total Worker Time],
qs.total_worker_time/qs.execution_count AS [Avg Worker Time],
qs.total_elapsed_time AS [Total Elapsed Time],
qs.total_elapsed_time/qs.execution_count AS [Avg Elapsed Time],
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
CONVERT(nvarchar(25), qs.last_execution_time, 20) AS [Last Execution Time],
CONVERT(nvarchar(25), qs.creation_time, 20) AS [Plan Cached Time]
CASE WHEN CONVERT(nvarchar(max), qp.query_plan) COLLATE Latin1_General_BIN2 LIKE N'%<MissingIndexes>%' THEN 1 ELSE 0 END AS [Has Missing Index],
qs.last_execution_time AS [Last Execution Time], qs.creation_time AS [Creation Time]
--,t.[text] AS [Complete Query Text], qp.query_plan AS [Query Plan] -- uncomment out these columns if not copying results to Excel
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(plan_handle) AS qp
WHERE t.dbid = DB_ID()
AND DATEDIFF(Minute, qs.creation_time, GETDATE()) > 0
ORDER BY qs.execution_count DESC OPTION (RECOMPILE);
------

Expand Down
2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '2.1.14'
ModuleVersion = '2.1.15'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
10 changes: 9 additions & 1 deletion public/Backup-DbaDatabase.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function Backup-DbaDatabase {
timestamp - will be replaced with the timestamp (either the default, or the format provided)
backuptype - will be replaced with Full, Log or Differential as appropriate
.PARAMETER NoAppendDbNameInPath
A switch that will prevent to systematically appended dbname to the path when creating the backup file path
.PARAMETER CopyOnly
If this switch is enabled, CopyOnly backups will be taken. By default function performs a normal backup, these backups interfere with the restore chain of the database. CopyOnly backups will not interfere with the restore chain of the database.
Expand Down Expand Up @@ -217,6 +220,7 @@ function Backup-DbaDatabase {
[string]$FilePath,
[switch]$IncrementPrefix,
[switch]$ReplaceInName,
[switch]$NoAppendDbNameInPath,
[switch]$CopyOnly,
[ValidateSet('Full', 'Log', 'Differential', 'Diff', 'Database')]
[string]$Type = 'Database',
Expand Down Expand Up @@ -661,7 +665,11 @@ function Backup-DbaDatabase {
for ($i = 0; $i -lt $FinalBackupPath.Count; $i++) {
$parent = [IO.Path]::GetDirectoryName($FinalBackupPath[$i])
$leaf = [IO.Path]::GetFileName($FinalBackupPath[$i])
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
if ($NoAppendDbNameInPath) {
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $leaf)
} else {
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions public/ConvertTo-DbaDataTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ function ConvertTo-DbaDataTable {
}
}
$specialType = 'Size'
} elseif ($type -eq 'Dataplat.Dbatools.Utility.DbaDateTime') {
$special = $true
$value = [System.DateTime]$value.DateTime
$type = 'System.DateTime'
$specialType = 'DateTime'
} elseif (-not ($type -in $types)) {
# All types which are not found in the array will be converted into strings.
# In this way we don't ignore it completely and it will be clear in the end why it looks as it does.
Expand Down Expand Up @@ -217,6 +222,9 @@ function ConvertTo-DbaDataTable {
$Value.$TimeSpanType
}
}
'DateTime' {
return [System.DateTime]$Value.DateTime
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions public/New-DbaAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ function New-DbaAvailabilityGroup {
.PARAMETER Name
The name of the Availability Group.
.PARAMETER IsContained
Builds the Availability Group as contained. Only supported in SQL Server 2022 or higher.
https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/contained-availability-groups-overview
.PARAMETER ReuseSystemDatabases
Used when rebuilding an availability group with the same name, where system databases already exist for the contained availability group.
.PARAMETER DtcSupport
Indicates whether the DtcSupport is enabled
Expand Down Expand Up @@ -219,6 +227,11 @@ function New-DbaAvailabilityGroup {
Creates a basic availability group named BAG1 on sql2016std and does not confirm when setting up
.EXAMPLE
PS C:\> New-DbaAvailabilityGroup -Primary sql2022n01 -Secondary sql2022n02 -Name AgContained -IsContained
Creates a contained availability group named AgContained on nodes sql2022n01 and sql2022n02
.EXAMPLE
PS C:\> New-DbaAvailabilityGroup -Primary sql2016b -Name AG1 -Dhcp -Database db1 -UseLastBackup
Expand Down Expand Up @@ -268,6 +281,8 @@ function New-DbaAvailabilityGroup {

[parameter(Mandatory)]
[string]$Name,
[switch]$IsContained,
[switch]$ReuseSystemDatabases,
[switch]$DtcSupport,
[ValidateSet('Wsfc', 'External', 'None')]
[string]$ClusterType = (Get-DbatoolsConfigValue -FullName 'AvailabilityGroups.Default.ClusterType' -Fallback 'Wsfc'),
Expand Down Expand Up @@ -366,6 +381,16 @@ function New-DbaAvailabilityGroup {
return
}

if ($IsContained -and $server.VersionMajor -lt 16) {
Stop-Function -Message "Contained availability groups are only supported in SQL Server 2022 and above" -Target $Primary
return
}

if ($ReuseSystemDatabases -and $IsContained -eq $false) {
Stop-Function -Message "Reuse system databases is only applicable in contained availability groups" -Target $Primary
return
}

Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Checking requirements"
$requirementsFailed = $false

Expand Down Expand Up @@ -499,6 +524,11 @@ function New-DbaAvailabilityGroup {
$ag.ClusterType = $ClusterType
}

if ($server.VersionMajor -ge 16) {
$ag.IsContained = $IsContained
$ag.ReuseSystemDatabases = $ReuseSystemDatabases
}

if ($PassThru) {
$defaults = 'LocalReplicaRole', 'Name as AvailabilityGroup', 'PrimaryReplicaServerName as PrimaryReplica', 'AutomatedBackupPreference', 'AvailabilityReplicas', 'AvailabilityDatabases', 'AvailabilityGroupListeners'
return (Select-DefaultView -InputObject $ag -Property $defaults)
Expand Down
Loading

0 comments on commit 6c7cb4b

Please sign in to comment.