Posted in
Windows Powershell |
No Comment | 1,958 views | 05/05/2016 16:39
You can get detailed info about SQL Server Availability Groups via following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| $MSSQLServerManager = New-Object 'Microsoft.SqlServer.Management.SMO.Server'
# Get SQL Availability Groups
$HostSQLAvailabilityGroup = @($MSSQLServerManager.AvailabilityGroups)[0]
# Get SQL Availability Groups Properties
$HostSQLAvailabilityGroupName = $HostSQLAvailabilityGroup.Name;
$HostSQLAvailabilityGroupID = $HostSQLAvailabilityGroup.Id;
$HostSQLAvailabilityGroupGuid = $HostSQLAvailabilityGroup.UniqueId;
$HostSQLLocalReplicaRole = $HostSQLAvailabilityGroup.LocalReplicaRole;
$HostSQLAutomatedBackupPreference = $HostSQLAvailabilityGroup.AutomatedBackupPreference;
$HostSQLFailureConditionLevel = $HostSQLAvailabilityGroup.FailureConditionLevel;
$HostSQLPrimaryReplicaServerName = $HostSQLAvailabilityGroup.PrimaryReplicaServerName;
$HostSQLHealthCheckTimeout = $HostSQLAvailabilityGroup.HealthCheckTimeout; |
$MSSQLServerManager = New-Object 'Microsoft.SqlServer.Management.SMO.Server'
# Get SQL Availability Groups
$HostSQLAvailabilityGroup = @($MSSQLServerManager.AvailabilityGroups)[0]
# Get SQL Availability Groups Properties
$HostSQLAvailabilityGroupName = $HostSQLAvailabilityGroup.Name;
$HostSQLAvailabilityGroupID = $HostSQLAvailabilityGroup.Id;
$HostSQLAvailabilityGroupGuid = $HostSQLAvailabilityGroup.UniqueId;
$HostSQLLocalReplicaRole = $HostSQLAvailabilityGroup.LocalReplicaRole;
$HostSQLAutomatedBackupPreference = $HostSQLAvailabilityGroup.AutomatedBackupPreference;
$HostSQLFailureConditionLevel = $HostSQLAvailabilityGroup.FailureConditionLevel;
$HostSQLPrimaryReplicaServerName = $HostSQLAvailabilityGroup.PrimaryReplicaServerName;
$HostSQLHealthCheckTimeout = $HostSQLAvailabilityGroup.HealthCheckTimeout;
You can also check other properties by listing all properties of $HostSQLAvailabilityGroup.