Skip to content

Commit f73e441

Browse files
Get-DbaAgDatabase - Add -ExcludeDatabase parameter (#10269)
1 parent 5590bc3 commit f73e441

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

public/Get-DbaAgDatabase.ps1

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function Get-DbaAgDatabase {
2626
Specifies which availability group databases to return information for. Accepts multiple database names with tab completion.
2727
Use this to focus on specific databases when troubleshooting AG issues or monitoring particular applications.
2828
29+
.PARAMETER ExcludeDatabase
30+
Specifies one or more databases to exclude from the results using exact name matching.
31+
Use this to filter out specific databases like test or staging environments from your results.
32+
2933
.PARAMETER InputObject
3034
Accepts availability group objects from Get-DbaAvailabilityGroup via pipeline input.
3135
Use this when you want to chain commands to get database details from already retrieved availability groups.
@@ -108,6 +112,11 @@ function Get-DbaAgDatabase {
108112
109113
Returns all the databases in the availability group AG101 on sql2017a
110114
115+
.EXAMPLE
116+
PS C:\> Get-DbaAgDatabase -SqlInstance sql2017a -ExcludeDatabase TestDB,StagingDB
117+
118+
Returns all the databases in each availability group found on sql2017a, excluding TestDB and StagingDB.
119+
111120
.EXAMPLE
112121
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlcluster -AvailabilityGroup SharePoint | Get-DbaAgDatabase -Database Sharepoint_Config
113122
@@ -119,6 +128,7 @@ function Get-DbaAgDatabase {
119128
[PSCredential]$SqlCredential,
120129
[string[]]$AvailabilityGroup,
121130
[string[]]$Database,
131+
[string[]]$ExcludeDatabase,
122132
[parameter(ValueFromPipeline)]
123133
[Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]]$InputObject,
124134
[switch]$EnableException
@@ -134,9 +144,8 @@ function Get-DbaAgDatabase {
134144
}
135145

136146
foreach ($db in $InputObject.AvailabilityDatabases) {
137-
if ($Database) {
138-
if ($db.Name -notin $Database) { continue }
139-
}
147+
if ($Database -and $db.Name -notin $Database) { continue }
148+
if ($ExcludeDatabase -and $db.Name -in $ExcludeDatabase) { continue }
140149
$ag = $db.Parent
141150
$server = $db.Parent.Parent
142151
Add-Member -Force -InputObject $db -MemberType NoteProperty -Name ComputerName -Value $server.ComputerName

tests/Get-DbaAgDatabase.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Describe $CommandName -Tag UnitTests {
1515
"SqlCredential",
1616
"AvailabilityGroup",
1717
"Database",
18+
"ExcludeDatabase",
1819
"InputObject",
1920
"EnableException"
2021
)

0 commit comments

Comments
 (0)