forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-InstallNamedInstanceInFailoverClusterFirstNode.ps1
123 lines (104 loc) · 5.77 KB
/
4-InstallNamedInstanceInFailoverClusterFirstNode.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<#
.EXAMPLE
This example shows how to install the first node in a SQL Server failover cluster.
.NOTES
This example assumes that a Failover Cluster is already present with a Cluster Name Object (CNO), IP-address.
This example also assumes that that all necessary shared disks is present, and formatted with the correct
drive letter, to accomdate the paths used during SQL Server setup. Minimum is one shared disk.
This example also assumes that the Cluster Name Object (CNO) has the permission to manage Computer Objects in
the Organizational Unit (OU) where the CNO Computer Object resides in Active Directory. This is neccessary
so that SQL Server setup can create a Virtual Computer Object (VCO) for the cluster group
(Windows Server 2012 R2 and earlier) or cluster role (Windows Server 2016 and later). Also so that the
Virtual Computer Object (VCO) can be removed when the Failover CLuster instance is uninstalled.
See the DSC resources xFailoverCluster, StorageDsc and iSCSIDsc for information how to setup a failover cluster
with DSC.
The resource is run using the SYSTEM account, but the setup is run using impersonation, with the credentials in
SetupCredential, when Action is 'InstallFailoverCluster'.
Assumes the credentials assigned to SourceCredential have read permission on the share and on the UNC path.
The media will be copied locally, using impersonation with the credentials provided in SourceCredential, so
that the impersonated credentials in SetupCredential can access the media locally.
Setup cannot be run using PsDscRunAsCredential at this time (see issue #405 and issue #444). That
also means that at this time PsDscRunAsCredential can not be used to access media on the UNC share.
There is currently a bug that prevents the resource to logon to the instance if the current node is not the
active node. This is beacuse the resource tries to logon using the SYSTEM account instead of the credentials
in SetupCredential, and the resource does not currently support the built-in PsDscRunAsCredential either (see
issue #444).
#>
Configuration Example
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[System.Management.Automation.PSCredential]
$SqlInstallCredential,
[Parameter()]
[ValidateNotNullorEmpty()]
[System.Management.Automation.PSCredential]
$SqlAdministratorCredential = $SqlInstallCredential,
[Parameter(Mandatory = $true)]
[ValidateNotNullorEmpty()]
[System.Management.Automation.PSCredential]
$SqlServiceCredential,
[Parameter()]
[ValidateNotNullorEmpty()]
[System.Management.Automation.PSCredential]
$SqlAgentServiceCredential = $SqlServiceCredential
)
Import-DscResource -ModuleName SqlServerDsc
node localhost
{
#region Install prerequisites for SQL Server
WindowsFeature 'NetFramework35'
{
Name = 'NET-Framework-Core'
Source = '\\fileserver.company.local\images$\Win2k12R2\Sources\Sxs' # Assumes built-in Everyone has read permission to the share and path.
Ensure = 'Present'
}
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
#endregion Install prerequisites for SQL Server
#region Install SQL Server Failover Cluster
SqlSetup 'InstallNamedInstanceNode1-INST2016'
{
Action = 'InstallFailoverCluster'
ForceReboot = $false
UpdateEnabled = 'False'
SourcePath = '\\fileserver.company.local\images$\SQL2016RTM'
SourceCredential = $SqlInstallCredential
InstanceName = 'INST2016'
Features = 'SQLENGINE,AS'
InstallSharedDir = 'C:\Program Files\Microsoft SQL Server'
InstallSharedWOWDir = 'C:\Program Files (x86)\Microsoft SQL Server'
InstanceDir = 'C:\Program Files\Microsoft SQL Server'
SQLCollation = 'Finnish_Swedish_CI_AS'
SQLSvcAccount = $SqlServiceCredential
AgtSvcAccount = $SqlAgentServiceCredential
SQLSysAdminAccounts = 'COMPANY\SQL Administrators', $SqlAdministratorCredential.UserName
ASSvcAccount = $SqlServiceCredential
ASSysAdminAccounts = 'COMPANY\SQL Administrators', $SqlAdministratorCredential.UserName
# Drive D: must be a shared disk.
InstallSQLDataDir = 'D:\MSSQL\Data'
SQLUserDBDir = 'D:\MSSQL\Data'
SQLUserDBLogDir = 'D:\MSSQL\Log'
SQLTempDBDir = 'D:\MSSQL\Temp'
SQLTempDBLogDir = 'D:\MSSQL\Temp'
SQLBackupDir = 'D:\MSSQL\Backup'
ASConfigDir = 'D:\AS\Config'
ASDataDir = 'D:\AS\Data'
ASLogDir = 'D:\AS\Log'
ASBackupDir = 'D:\AS\Backup'
ASTempDir = 'D:\AS\Temp'
FailoverClusterNetworkName = 'TESTCLU01A'
FailoverClusterIPAddress = '192.168.0.46'
FailoverClusterGroupName = 'TESTCLU01A'
PsDscRunAsCredential = $SqlInstallCredential
DependsOn = '[WindowsFeature]NetFramework35', '[WindowsFeature]NetFramework45'
}
#region Install SQL Server Failover Cluster
}
}