< Back
Get-DbaAvailabilityGroup
Post
NAME Get-DbaAvailabilityGroup
SYNOPSIS
Returns availability group objects from a SQL Server instance.
SYNTAX
Get-DbaAvailabilityGroup [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-AvailabilityGroup] <System.String[]>] [-IsPrimary <Switch>] [-EnableException
<Switch>] [<CommonParameters>]
DESCRIPTION
Returns availability group objects from a SQL Server instance.
Default view provides most common set of properties for information on the Availability Group(s).
PARAMETERS
-AvailabilityGroup [<System.String[]>]
Return only specific availability groups.
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
-IsPrimary [<Switch>]
If this switch is enabled, a boolean indicating whether SqlInstance is the Primary replica in the AG is
returned.
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. You must have sysadmin access and 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) | Chrissy LeMaire (@cl)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a
Returns basic information on all the Availability Group(s) found on sqlserver2014a.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a
Shows basic information on the Availability Group AG-a on sqlserver2014a.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object *
Returns full object properties on all Availability Group(s) on sqlserver2014a.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object -ExpandProperty
PrimaryReplicaServerName
Returns the SQL Server instancename of the primary replica as a string
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a -IsPrimary
Returns true/false if the server, sqlserver2014a, is the primary replica for AG-a Availability Group.
RELATED LINKS
https://dbatools.io/Get-DbaAvailabilityGroup
SYNOPSIS
Returns availability group objects from a SQL Server instance.
SYNTAX
Get-DbaAvailabilityGroup [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>
[[-SqlCredential] <Pscredential>] [[-AvailabilityGroup] <System.String[]>] [-IsPrimary <Switch>] [-EnableException
<Switch>] [<CommonParameters>]
DESCRIPTION
Returns availability group objects from a SQL Server instance.
Default view provides most common set of properties for information on the Availability Group(s).
PARAMETERS
-AvailabilityGroup [<System.String[]>]
Return only specific availability groups.
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
-IsPrimary [<Switch>]
If this switch is enabled, a boolean indicating whether SqlInstance is the Primary replica in the AG is
returned.
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. You must have sysadmin access and 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) | Chrissy LeMaire (@cl)
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a
Returns basic information on all the Availability Group(s) found on sqlserver2014a.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a
Shows basic information on the Availability Group AG-a on sqlserver2014a.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object *
Returns full object properties on all Availability Group(s) on sqlserver2014a.
-------------------------- EXAMPLE 4 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object -ExpandProperty
PrimaryReplicaServerName
Returns the SQL Server instancename of the primary replica as a string
-------------------------- EXAMPLE 5 --------------------------
PS C:\\>Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a -IsPrimary
Returns true/false if the server, sqlserver2014a, is the primary replica for AG-a Availability Group.
RELATED LINKS
https://dbatools.io/Get-DbaAvailabilityGroup