---
title: "Get-DbaAvailabilityGroup"
description: "Retrieves Availability Group configuration and status information from SQL Server instances."
url: "https://dbatools.io/Get-DbaAvailabilityGroup/"
availability: "Windows, Linux, macOS"
tags: ["AG", "HA"]
author: "Shawn Melton (@wsmelton) | Chrissy LeMaire (@cl)"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaAvailabilityGroup.ps1"
last_updated: "2024-01-01"
---

# Get-DbaAvailabilityGroup

## 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

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

```

## Examples

### Example 1: Returns basic information on all the Availability Group(s) found on sqlserver2014a

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a
```

### Example 2: Shows basic information on the Availability Group AG-a on sqlserver2014a

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a
```

### Example 3: Returns full object properties on all Availability Group(s) on sqlserver2014a

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object *
```

### Example 4: Returns the SQL Server instancename of the primary replica as a string

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a | Select-Object -ExpandProperty PrimaryReplicaServerName
```

### Example 5: Returns true/false if the server, sqlserver2014a, is the primary replica for AG-a Availability Group

```powershell
PS C:\> Get-DbaAvailabilityGroup -SqlInstance sqlserver2014a -AvailabilityGroup AG-a -IsPrimary
```

### 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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| 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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| 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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

## 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 *.

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
