Skip to content

Commit 6c7cb4b

Browse files
Merge branch 'development'
2 parents 5970711 + 22c7bc9 commit 6c7cb4b

17 files changed

+96
-33
lines changed

.github/workflows/gallery.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install and cache PowerShell modules
2525
uses: potatoqualitee/psmodulecache@v5.2
2626
with:
27-
modules-to-cache: dbatools.library:2024.3.9
27+
modules-to-cache: dbatools.library:2024.4.12
2828

2929
- name: Download dbatools from Gallery
3030
run: |

bin/dbatools-buildref-index.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"LastUpdated": "2024-04-11T00:00:00",
2+
"LastUpdated": "2024-05-16T00:00:00",
33
"Data": [
44
{
55
"Version": "8.0.47",
@@ -4683,6 +4683,11 @@
46834683
{
46844684
"Version": "16.0.4120",
46854685
"KBList": "5036343"
4686+
},
4687+
{
4688+
"CU": "CU13",
4689+
"Version": "16.0.4125",
4690+
"KBList": "5036432"
46864691
}
46874692
]
46884693
}

bin/dbatools-index.json

3.42 KB
Binary file not shown.

bin/diagnosticquery/SQLServerDiagnosticQueries_2012.sql

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2014.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2016.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2016SP2.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2017.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2019.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

bin/diagnosticquery/SQLServerDiagnosticQueries_2022.sql

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

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

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

dbatools.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
RootModule = 'dbatools.psm1'
1212

1313
# Version number of this module.
14-
ModuleVersion = '2.1.14'
14+
ModuleVersion = '2.1.15'
1515

1616
# ID used to uniquely identify this module
1717
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'

public/Backup-DbaDatabase.ps1

+9-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ function Backup-DbaDatabase {
5454
timestamp - will be replaced with the timestamp (either the default, or the format provided)
5555
backuptype - will be replaced with Full, Log or Differential as appropriate
5656
57+
.PARAMETER NoAppendDbNameInPath
58+
A switch that will prevent to systematically appended dbname to the path when creating the backup file path
59+
5760
.PARAMETER CopyOnly
5861
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.
5962
@@ -217,6 +220,7 @@ function Backup-DbaDatabase {
217220
[string]$FilePath,
218221
[switch]$IncrementPrefix,
219222
[switch]$ReplaceInName,
223+
[switch]$NoAppendDbNameInPath,
220224
[switch]$CopyOnly,
221225
[ValidateSet('Full', 'Log', 'Differential', 'Diff', 'Database')]
222226
[string]$Type = 'Database',
@@ -661,7 +665,11 @@ function Backup-DbaDatabase {
661665
for ($i = 0; $i -lt $FinalBackupPath.Count; $i++) {
662666
$parent = [IO.Path]::GetDirectoryName($FinalBackupPath[$i])
663667
$leaf = [IO.Path]::GetFileName($FinalBackupPath[$i])
664-
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
668+
if ($NoAppendDbNameInPath) {
669+
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $leaf)
670+
} else {
671+
$FinalBackupPath[$i] = [IO.Path]::Combine($parent, $dbName, $leaf)
672+
}
665673
}
666674
}
667675

public/ConvertTo-DbaDataTable.ps1

+8
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ function ConvertTo-DbaDataTable {
166166
}
167167
}
168168
$specialType = 'Size'
169+
} elseif ($type -eq 'Dataplat.Dbatools.Utility.DbaDateTime') {
170+
$special = $true
171+
$value = [System.DateTime]$value.DateTime
172+
$type = 'System.DateTime'
173+
$specialType = 'DateTime'
169174
} elseif (-not ($type -in $types)) {
170175
# All types which are not found in the array will be converted into strings.
171176
# In this way we don't ignore it completely and it will be clear in the end why it looks as it does.
@@ -217,6 +222,9 @@ function ConvertTo-DbaDataTable {
217222
$Value.$TimeSpanType
218223
}
219224
}
225+
'DateTime' {
226+
return [System.DateTime]$Value.DateTime
227+
}
220228
}
221229
}
222230

public/New-DbaAvailabilityGroup.ps1

+30
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ function New-DbaAvailabilityGroup {
5656
.PARAMETER Name
5757
The name of the Availability Group.
5858
59+
.PARAMETER IsContained
60+
Builds the Availability Group as contained. Only supported in SQL Server 2022 or higher.
61+
62+
https://learn.microsoft.com/en-us/sql/database-engine/availability-groups/windows/contained-availability-groups-overview
63+
64+
.PARAMETER ReuseSystemDatabases
65+
Used when rebuilding an availability group with the same name, where system databases already exist for the contained availability group.
66+
5967
.PARAMETER DtcSupport
6068
Indicates whether the DtcSupport is enabled
6169
@@ -219,6 +227,11 @@ function New-DbaAvailabilityGroup {
219227
220228
Creates a basic availability group named BAG1 on sql2016std and does not confirm when setting up
221229
230+
.EXAMPLE
231+
PS C:\> New-DbaAvailabilityGroup -Primary sql2022n01 -Secondary sql2022n02 -Name AgContained -IsContained
232+
233+
Creates a contained availability group named AgContained on nodes sql2022n01 and sql2022n02
234+
222235
.EXAMPLE
223236
PS C:\> New-DbaAvailabilityGroup -Primary sql2016b -Name AG1 -Dhcp -Database db1 -UseLastBackup
224237
@@ -268,6 +281,8 @@ function New-DbaAvailabilityGroup {
268281

269282
[parameter(Mandatory)]
270283
[string]$Name,
284+
[switch]$IsContained,
285+
[switch]$ReuseSystemDatabases,
271286
[switch]$DtcSupport,
272287
[ValidateSet('Wsfc', 'External', 'None')]
273288
[string]$ClusterType = (Get-DbatoolsConfigValue -FullName 'AvailabilityGroups.Default.ClusterType' -Fallback 'Wsfc'),
@@ -366,6 +381,16 @@ function New-DbaAvailabilityGroup {
366381
return
367382
}
368383

384+
if ($IsContained -and $server.VersionMajor -lt 16) {
385+
Stop-Function -Message "Contained availability groups are only supported in SQL Server 2022 and above" -Target $Primary
386+
return
387+
}
388+
389+
if ($ReuseSystemDatabases -and $IsContained -eq $false) {
390+
Stop-Function -Message "Reuse system databases is only applicable in contained availability groups" -Target $Primary
391+
return
392+
}
393+
369394
Write-ProgressHelper -StepNumber ($stepCounter++) -Message "Checking requirements"
370395
$requirementsFailed = $false
371396

@@ -499,6 +524,11 @@ function New-DbaAvailabilityGroup {
499524
$ag.ClusterType = $ClusterType
500525
}
501526

527+
if ($server.VersionMajor -ge 16) {
528+
$ag.IsContained = $IsContained
529+
$ag.ReuseSystemDatabases = $ReuseSystemDatabases
530+
}
531+
502532
if ($PassThru) {
503533
$defaults = 'LocalReplicaRole', 'Name as AvailabilityGroup', 'PrimaryReplicaServerName as PrimaryReplica', 'AutomatedBackupPreference', 'AvailabilityReplicas', 'AvailabilityDatabases', 'AvailabilityGroupListeners'
504534
return (Select-DefaultView -InputObject $ag -Property $defaults)

0 commit comments

Comments
 (0)