-
Notifications
You must be signed in to change notification settings - Fork 95
/
Update RegisterAllProvidersIP and HostRecordTTL in all AG Clusters.ps1
47 lines (37 loc) · 1.79 KB
/
Update RegisterAllProvidersIP and HostRecordTTL in all AG Clusters.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<#
Update RegisterAllProvidersIP and HostRecordTTL in all AG Clusters
==================================================================
Author: Eitan Blumin | https://madeiradata.com
Date: 2021-06-21
Description:
This script is based on the recommendations on this page:
https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/create-or-configure-an-availability-group-listener-sql-server#FollowUp
This should be used for multi-subnet environments where it's NOT possible
for the applications to set "MultiSubnetFailover=True" in their connection strings.
This script is especially useful for when you have multiple AG clusters because it
automatically detects all failover clusters on the current machine.
If RegisterAllProvidersIP and/or HostRecordTTL should be changed, the relevant commands
will be printed out but will NOT actually be executed.
When ready, copy and paste the result commands and run them to actually apply the changes.
IMPORTANT NOTE: The output commands include restarting the cluster resources.
#>
Import-Module FailoverClusters
cls
Get-ClusterResource | Where ResourceType -eq "Network Name" | ForEach {
$Changed = $false
$RegisterAllProvidersIP = $_ | Get-ClusterParameter -Name "RegisterAllProvidersIP"
if ($RegisterAllProvidersIP.Value -eq 1) {
"Get-ClusterResource '$($_.Name)' | Set-ClusterParameter RegisterAllProvidersIP 0"
$Changed = $true
}
$HostRecordTTL = $_ | Get-ClusterParameter -Name "HostRecordTTL"
if ($HostRecordTTL.Value -gt 300) {
"Get-ClusterResource '$($_.Name)' | Set-ClusterParameter HostRecordTTL 300"
$Changed = $true
}
if ($Changed) {
"Stop-ClusterResource '$($_.Name)'"
"Start-ClusterResource '$($_.Name)'"
"Start-Clustergroup '$($_.OwnerGroup)'"
}
}