-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathMssqlVmConfig.ps1
70 lines (62 loc) · 2.37 KB
/
MssqlVmConfig.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
configuration MssqlVmConfig {
param (
[Parameter(Mandatory = $true)]
[String]$ComputerName
)
Import-DscResource -ModuleName 'PSDscResources'
Import-DscResource -ModuleName 'xDSCDomainjoin'
Import-DscResource -ModuleName 'NetworkingDsc'
Import-DscResource -ModuleName 'SqlServerDsc'
Import-DscResource -ModuleName 'ActiveDirectoryDsc'
$domain = Get-AutomationVariable -Name 'adds_domain_name'
$localAdminCredential = Get-AutomationPSCredential 'bootstrapadmin'
$domainAdminCredential = Get-AutomationPSCredential 'domainadmin'
$domainAdminShortCredential = Get-AutomationPSCredential 'domainadminshort'
node $ComputerName {
xDSCDomainjoin 'JoinDomain' {
Domain = $domain
Credential = $domainAdminCredential
}
Firewall 'MssqlFirewallRule' {
Name = 'MssqlFirewallRule'
DisplayName = 'Microsoft SQL Server database engine.'
Ensure = 'Present'
Enabled = 'True'
Profile = ('Domain', 'Private')
Direction = 'InBound'
LocalPort = ('1433')
Protocol = 'TCP'
DependsOn = '[xDSCDomainjoin]JoinDomain'
}
SqlLogin 'DomainAdmin' {
Name = $domainAdminShortCredential.UserName
LoginType = 'WindowsUser'
InstanceName = 'MSSQLSERVER'
Ensure = 'Present'
DependsOn = '[xDSCDomainjoin]JoinDomain'
PSDscRunAsCredential = $localAdminCredential
}
SqlRole 'sysadmin' {
ServerRoleName = 'sysadmin'
MembersToInclude = $domainAdminShortCredential.UserName
InstanceName = 'MSSQLSERVER'
Ensure = 'Present'
DependsOn = '[SqlLogin]DomainAdmin'
PSDscRunAsCredential = $localAdminCredential
}
WindowsFeature 'RSAT-AD-PowerShell' {
Name = 'RSAT-AD-PowerShell'
Ensure = 'Present'
DependsOn = '[xDSCDomainjoin]JoinDomain'
}
ADGroup 'DatabaseServers' {
GroupName = 'DatabaseServers'
GroupScope = 'Global'
Category = 'Security'
MembersToInclude = "$ComputerName$"
Credential = $domainAdminCredential
Ensure = 'Present'
DependsOn = '[WindowsFeature]RSAT-AD-PowerShell'
}
}
}