Test-SqlAvailabilityReplica

Evaluates the health of availability replicas by evaluating SQL Server policy based management (PBM) policies.
Test-SqlAvailabilityReplica [-InputObject*] <AvailabilityReplica[]> [-AllowUserPolicies] [-NoRefresh][-ShowPolicyDetails] [<CommonParameters>]
Test-SqlAvailabilityReplica [[-Path] <string[]>] [-AllowUserPolicies] [-NoRefresh] [-ShowPolicyDetails][<CommonParameters>]

The Test-SqlAvailabilityReplica cmdlet assesses the health of availability replicas 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 <AvailabilityReplica[]>

  • This value is required
  • Accepts pipeline input ByValue

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

-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 paths to one or more availability replicas. 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.AvailabilityReplica

Examples
  1. This command evaluates the health of the availability replica named ‘MyReplica’ in the availability group ‘MyAg’ and outputs a brief summary:
    C:PS> Test-SqlAvailabilityReplica -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAgAvailabilityReplicasMyReplica
    
  2. This command evaluates the health of all availability replicas in the availability group ‘MyAg’ and outputs a brief summary for each replica:
    C:PS> Get-ChildItem SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAgAvailabilityReplicas | Test-SqlAvailabilityReplica
    
  3. This command evaluates the health of the availability replica named ‘MyReplica’ in the availability group ‘MyAg’ and outputs the evaluation results for each policy-based management (PBM) policy that was executed:
    C:PS> Test-SqlAvailabilityReplica -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAgAvailabilityReplicasMyReplica -ShowPolicyDetails
    
  4. This command evaluates the health of the availability replica named ‘MyReplica’ in the availability group ‘MyAg’:
    C:PS> Test-SqlAvailabilityReplica -Path SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAgAvailabilityReplicasMyReplica -AllowUserPolicies
    

    User-defined policies are included in this evaluation.

  5. This command shows all availability replicas with a health state of “Error” in the availability group ‘MyAg’:
    C:PS> Get-ChildItem SQLSERVER:SqlComputerInstanceAvailabilityGroupsMyAgAvailabilityReplicas | Test-SqlAvailabilityReplica | Where-Object { $_.HealthState -eq "Error" }
    
Additional Notes
 
Related Links