Thor Logo dbatools

Get-DbaAvailabilityGroup

View Source
Shawn Melton (@wsmelton) , Chrissy LeMaire (@cl)
Windows, Linux, macOS

Synopsis

Retrieves Availability Group configuration and status information from SQL Server instances.

Description

Retrieves detailed Availability Group information including replica roles, cluster configuration, database membership, and listener details from SQL Server 2012+ instances.

This command helps DBAs monitor AG health, identify primary replicas for failover planning, and generate inventory reports for compliance or troubleshooting. The default view shows essential properties like replica roles, primary replica location, and cluster type, while the full object contains comprehensive AG configuration details.

Syntax

Get-DbaAvailabilityGroup
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-AvailabilityGroup] <String[]>]
    [-IsPrimary]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

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.

Required Parameters

-SqlInstance

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2012 or higher.

PropertyValue
Alias
RequiredTrue
Pipelinetrue (ByValue)
Default Value

Optional Parameters

-SqlCredential

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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-AvailabilityGroup

Specifies one or more Availability Group names to filter results to specific AGs. Supports wildcards for pattern matching.
Use this when you need to check status or configuration of particular AGs rather than retrieving information for all AGs on the instance.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default Value
-IsPrimary

Returns a boolean value indicating whether the queried SQL Server instance is currently serving as the Primary replica for each Availability Group.
Use this switch when you need to quickly identify which replica in your AG topology is currently primary, particularly useful for automated failover scripts or health monitoring.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse
-EnableException

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.

PropertyValue
Alias
RequiredFalse
Pipelinefalse
Default ValueFalse

Outputs

Microsoft.SqlServer.Management.Smo.AvailabilityGroup

Returns one AvailabilityGroup object per availability group found on the specified instance(s). Three custom properties are added to each object for convenience: ComputerName, InstanceName, and SqlInstance.

Default display properties (without -IsPrimary):

  • ComputerName: The computer name of the SQL Server instance hosting the availability group
  • InstanceName: The SQL Server instance name
  • SqlInstance: The full SQL Server instance name (computer\instance)
  • LocalReplicaRole: The role of the current replica in the availability group (Primary or Secondary)
  • AvailabilityGroup: Name of the availability group (from the Name property)
  • PrimaryReplica: The server name of the primary replica (from PrimaryReplicaServerName property)
  • ClusterType: Type of cluster supporting the availability group (Wsfc, External, None)
  • DtcSupportEnabled: Boolean indicating if Distributed Transaction Coordinator support is enabled
  • AutomatedBackupPreference: Preference for automated backups (Primary, SecondaryOnly, Secondary, None)
  • AvailabilityReplicas: Collection of replicas that are part of this availability group
  • AvailabilityDatabases: Collection of databases that are part of this availability group
  • AvailabilityGroupListeners: Collection of listeners configured for this availability group

Default display properties (with -IsPrimary):

  • ComputerName: The computer name of the SQL Server instance
  • InstanceName: The SQL Server instance name
  • SqlInstance: The full SQL Server instance name (computer\instance)
  • AvailabilityGroup: Name of the availability group (from the Name property)
  • IsPrimary: Boolean indicating whether the queried instance is the primary replica for this availability group

Additional properties available from the SMO AvailabilityGroup object:

  • Name: Name of the availability group
  • DtcSupportEnabled: Boolean for DTC support
  • AutomatedBackupPreference: Backup preference setting
  • FailureConditionLevel: Failure condition threshold level
  • HealthCheckTimeout: Health check timeout in milliseconds
  • BasicAvailabilityGroup: Boolean indicating if this is a basic availability group (SQL Server 2016+)
  • DatabaseHealthTrigger: Boolean for database health trigger setting
  • Urn: Uniform Resource Name for the SMO object All properties from the SMO AvailabilityGroup object are accessible by using Select-Object *.