forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLPush_SingleServer.ps1
More file actions
185 lines (169 loc) · 6.01 KB
/
Copy pathSQLPush_SingleServer.ps1
File metadata and controls
185 lines (169 loc) · 6.01 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#requires -Version 5
$computers = 'OHSQL1016'
$OutputPath = 'D:\DSCLocal'
$cim = New-CimSession -ComputerName $computers
#requires -Version 5
[DSCLocalConfigurationManager()]
Configuration LCM_Push
{
Param(
[string[]]$ComputerName
)
Node $ComputerName
{
Settings
{
AllowModuleOverwrite = $True
ConfigurationMode = 'ApplyAndAutoCorrect'
RefreshMode = 'Push'
RebootNodeIfNeeded = $True
}
}
}
foreach ($computer in $computers)
{
$GUID = (New-Guid).Guid
LCM_Push -ComputerName $Computer -OutputPath $OutputPath
Set-DSCLocalConfigurationManager -Path $OutputPath -CimSession $computer
}
Configuration SQLSA
{
Import-DscResource –Module PSDesiredStateConfiguration
Import-DscResource -Module xSQLServer
Node $AllNodes.NodeName
{
# Set LCM to reboot if needed
LocalConfigurationManager
{
AllowModuleOverwrite = $true
RebootNodeIfNeeded = $true
}
WindowsFeature "NET"
{
Ensure = "Present"
Name = "NET-Framework-Core"
Source = $Node.NETPath
}
if($Node.Features)
{
xSqlServerSetup ($Node.NodeName)
{
DependsOn = '[WindowsFeature]NET'
SourcePath = $Node.SourcePath
SetupCredential = $Node.InstallerServiceAccount
InstanceName = $Node.InstanceName
Features = $Node.Features
SQLSysAdminAccounts = $Node.AdminAccount
InstallSharedDir = "G:\Program Files\Microsoft SQL Server"
InstallSharedWOWDir = "G:\Program Files (x86)\Microsoft SQL Server"
InstanceDir = "G:\Program Files\Microsoft SQL Server"
InstallSQLDataDir = "G:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
SQLUserDBDir = "G:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
SQLUserDBLogDir = "L:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
SQLTempDBDir = "T:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
SQLTempDBLogDir = "L:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
SQLBackupDir = "G:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data"
}
xSqlServerFirewall ($Node.NodeName)
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
SourcePath = $Node.SourcePath
InstanceName = $Node.InstanceName
Features = $Node.Features
}
xSQLServerMemory ($Node.Nodename)
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
Ensure = "Present"
DynamicAlloc = $false
MinMemory = "256"
MaxMemory ="1024"
}
xSQLServerMaxDop($Node.Nodename)
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
Ensure = "Present"
DynamicAlloc = $true
}
xSQLServerLogin($Node.Nodename+"TestUser2")
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
Ensure = "Present"
Name = "TestUser2"
LoginCredential = $Node.InstallerServiceAccount
LoginType = "SQLLogin"
}
xSQLServerLogin($Node.Nodename+"TestUser1")
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
Ensure = "Present"
Name = "TestUser1"
LoginCredential = $Node.InstallerServiceAccount
LoginType = "SQLLogin"
}
xSQLServerDatabaseRole($Node.Nodename)
{
DependsOn = ("[xSqlServerSetup]" + $Node.NodeName)
Ensure = "Present"
Name = "TestUser1"
Database = "model"
Role ="db_Datareader"
}
xSQLDatabaseRecoveryModel($Node.Nodename)
{
DatabaseName = "TestDB"
RecoveryModel = "Full"
SqlServerInstance ="$($Node.NodeName)\$($Node.SQLInstanceName)"
}
xSQLServerDatabaseOwner($Node.Nodename)
{
Database = "TestDB"
Name = "TestUser2"
}
xSQLServerDatabasePermission($Node.Nodename)
{
Database = "Model"
Name = "TestUser1"
Permissions ="SELECT","DELETE"
}
xSQLServerDatabase($Node.Nodename)
{
Database = "Test3"
Ensure = "Present"
}
}
}
}
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = "*"
PSDscAllowPlainTextPassword = $true
PSDscAllowDomainUser =$true
NETPath = "\\ohhv003\SQLBuilds\SQLAutoInstall\WIN2012R2\sxs"
SourcePath = "\\ohhv003\SQLBuilds\SQLAutoInstall\SQL2012"
InstallerServiceAccount = Get-Credential -UserName Contoso\SQLAutoSvc -Message "Credentials to Install SQL Server"
AdminAccount = "Contoso\sqladmin"
}
)
}
ForEach ($computer in $computers) {
$ConfigurationData.AllNodes += @{
NodeName = $computer
InstanceName = "MSSQLSERVER"
Features = "SQLENGINE,IS,SSMS,ADV_SSMS"
}
$Destination = "\\"+$computer+"\\c$\Program Files\WindowsPowerShell\Modules"
Copy-Item 'C:\Program Files\WindowsPowerShell\Modules\xSQLServer' -Destination $Destination -Recurse -Force
}
SQLSA -ConfigurationData $ConfigurationData -OutputPath $OutputPath
#Push################################
foreach($Computer in $Computers)
{
Start-DscConfiguration -ComputerName $Computer -Path $OutputPath -Verbose -Wait -Force
}
#Ttest
foreach($Computer in $Computers)
{
test-dscconfiguration -ComputerName $Computer
}