< Back
Get-DbaAgDatabase
Post
NAME Get-DbaAgDatabase
SYNOPSIS
Gets availability group databases from a SQL Server instance.
SYNTAX
Get-DbaAgDatabase [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-AvailabilityGroup] <System.String[]>] [[-Database] <System.String[]>] [[-InputObject]
<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Gets availability group databases from a SQL Server instance.
Default view provides most common set of properties for information on the database in an availability group.
Information returned on the database will be specific to that replica, whether it is primary or a secondary.
PARAMETERS
-AvailabilityGroup [<System.String[]>]
Specify the availability groups to query.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.String[]>]
Specify the database or databases to return. This list is auto-populated from the server for tab completion.
Multiple databases can be specified. If none are specified all databases will be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>]
Enables piped input from Get-DbaAvailabilityGroup.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances. Server version must be SQL Server version 2012 or higher.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: AvailabilityGroup, HA, AG
Author: Shawn Melton (@wsmelton), https://wsmelton.github.io
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-DbaAgDatabase -SqlInstance sql2017a
Returns all the databases in each availability group found on sql2017a
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAgDatabase -SqlInstance sql2017a -AvailabilityGroup AG101
Returns all the databases in the availability group AG101 on sql2017a
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlcluster -AvailabilityGroup SharePoint -Database Sharepoint_Config
| Get-DbaAgDatabase
Returns the database Sharepoint_Config found in the availability group SharePoint on server sqlcluster
RELATED LINKS
https://dbatools.io/Get-DbaAgDatabase
SYNOPSIS
Gets availability group databases from a SQL Server instance.
SYNTAX
Get-DbaAgDatabase [[-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>] [[-SqlCredential]
<Pscredential>] [[-AvailabilityGroup] <System.String[]>] [[-Database] <System.String[]>] [[-InputObject]
<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>] [-EnableException <Switch>] [<CommonParameters>]
DESCRIPTION
Gets availability group databases from a SQL Server instance.
Default view provides most common set of properties for information on the database in an availability group.
Information returned on the database will be specific to that replica, whether it is primary or a secondary.
PARAMETERS
-AvailabilityGroup [<System.String[]>]
Specify the availability groups to query.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Database [<System.String[]>]
Specify the database or databases to return. This list is auto-populated from the server for tab completion.
Multiple databases can be specified. If none are specified all databases will be processed.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables
advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own
try/catch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-InputObject [<Microsoft.SqlServer.Management.Smo.AvailabilityGroup[]>]
Enables piped input from Get-DbaAvailabilityGroup.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]
The target SQL Server instance or instances. Server version must be SQL Server version 2012 or higher.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: AvailabilityGroup, HA, AG
Author: Shawn Melton (@wsmelton), https://wsmelton.github.io
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-DbaAgDatabase -SqlInstance sql2017a
Returns all the databases in each availability group found on sql2017a
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAgDatabase -SqlInstance sql2017a -AvailabilityGroup AG101
Returns all the databases in the availability group AG101 on sql2017a
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlcluster -AvailabilityGroup SharePoint -Database Sharepoint_Config
| Get-DbaAgDatabase
Returns the database Sharepoint_Config found in the availability group SharePoint on server sqlcluster
RELATED LINKS
https://dbatools.io/Get-DbaAgDatabase