-
Notifications
You must be signed in to change notification settings - Fork 3
/
EnableAlwaysOn.schema.psm1
90 lines (76 loc) · 3.01 KB
/
EnableAlwaysOn.schema.psm1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Configuration EnableAlwaysOn {
Param(
[Parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[string]
$Server,
[ValidateNotNullorEmpty()]
[string]
$SQLInstance = 'MSSQLSERVER',
[Parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$SqlInstallCredential,
[ValidateNotNullorEmpty()]
[string]
$HADRPort = 5022,
[ValidateNotNullorEmpty()]
[string]
$RestartTimeout = 120
)
Import-DscResource -ModuleName SqlServerDsc
# Adding the required service account to allow the cluster to log into SQL
SqlServerLogin AddNTServiceClusSvc {
Ensure = 'Present'
Name = 'NT SERVICE\ClusSvc'
LoginType = 'WindowsUser'
ServerName = = $Server
InstanceName = $SQLInstance
PsDscRunAsCredential = $SqlInstallCredential
}
# Add the required permissions to the cluster service login
SqlServerPermission AddNTServiceClusSvcPermissions {
DependsOn = '[SqlServerLogin]AddNTServiceClusSvc'
Ensure = 'Present'
ServerName = = $Server
InstanceName = $SQLInstance
Principal = 'NT SERVICE\ClusSvc'
Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState'
PsDscRunAsCredential = $SqlInstallCredential
}
# Create a DatabaseMirroring endpoint
SqlServerEndpoint HADREndpoint {
EndPointName = 'HADR'
Ensure = 'Present'
Port = $HADRPort
ServerName = = $Server
InstanceName = $SQLInstance
PsDscRunAsCredential = $SqlInstallCredential
}
SqlServerLogin AddSQLServiceAccount {
Ensure = 'Present'
Name = $SqlServiceCredential.UserName
LoginType = 'WindowsUser'
ServerName = = $Server
InstanceName = $SQLInstance
PsDscRunAsCredential = $SqlInstallCredential
}
SqlServerEndpointPermission SQLConfigureEndpointPermission {
Ensure = 'Present'
ServerName = = $Server
InstanceName = $SQLInstance
Name = 'HADR'
Principal = $SqlServiceCredential.UserName
Permission = 'CONNECT'
PsDscRunAsCredential = $SqlInstallCredential
DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerLogin]AddSQLServiceAccount'
}
SqlAlwaysOnService 'EnableAlwaysOn' {
Ensure = 'Present'
ServerName = $Server
InstanceName = $SQLInstance
RestartTimeout = $RestartTimeout
PsDscRunAsCredential = $SqlInstallCredential
}
}