Test-SqlAvailabilityGroup

Evaluates the health of an availability group by evaluating SQL Server policy based management (PBM) policies.
Test-SqlAvailabilityGroup [-AllowUserPolicies] [-InputObject <AvailabilityGroup[]>] [-NoRefresh][-ShowPolicyDetails] [<CommonParameters>]
Test-SqlAvailabilityGroup [[-Path] <string[]>] [-AllowUserPolicies] [-NoRefresh] [-ShowPolicyDetails][<CommonParameters>]

The Test-SqlAvailabilityGroup cmdlet assesses the health of an availability group by evaluating SQL Server policy based management (PBM) policies. You must have CONNECT, VIEW SERVER STATE, and VIEW ANY DEFINITION permissions to execute this cmdlet.

Parameters
-AllowUserPolicies [<SwitchParameter>]

Runs user policies found in the AlwaysOn policy categories.

-InputObject <AvailabilityGroup[]>

A collection of objects representing availability groups. This cmdlet will compute the health of these availability groups.

-NoRefresh [<SwitchParameter>]

When this parameter is set, the cmdlet will not manually refresh the objects specified by the -Path or -InputObject parameter.

-Path <string[]>

The path to the availability group. This is an optional parameter. If not specified, the value of this parameter defaults to the current working location.

-ShowPolicyDetails [<SwitchParameter>]

Shows the result of each policy evaluation performed by this cmdlet. The cmdlet outputs one object per policy evaluation, and this object has fields describing the results of evaluation (whether the policy passed or not, the policy name and category, and so forth).

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

Microsoft.SqlServer.Management.Smo.AvailabilityGroup

Examples
  1. This command evaluates the health of the availability group named ‘MyAg’ and outputs a brief summary:
    C:PS> Test-SqlAvailabilityGroup -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAg
    
  2. This command evaluates the health of all availability groups on the server instance ‘ComputerInstance’ and outputs a brief summary for each availability group:
    C:PS> Get-ChildItem SQLSERVER:SqlComputerInstanceAvailabilityGroups | Test-SqlAvailabilityGroup
    
  3. This command evaluates the health of the availability group named ‘MyAg’ and outputs the evaluation results for each policy-based management (PBM) policy that was executed:
    C:PS> Test-SqlAvailabilityGroup -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsAgName -ShowPolicyDetails
    
  4. This command evaluates the health of the availability group named ‘MyAg’:
    C:PS> Test-SqlAvailabilityGroup -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsAgName -AllowUserPolicies
    

    User-defined policies are included in this evaluation.

  5. This command shows all availability groups with a health state of “Error” on the server instance ‘ComputerInstance’:
    C:PS> Get-ChildItem SQLSERVER:SqlComputerInstanceAvailabilityGroups | Test-SqlAvailabilityGroup | Where-Object { $_.HealthState -eq "Error" }
    
Additional Notes
 
Related Links