-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateDomainForest.Lab.ps1
165 lines (138 loc) · 4.32 KB
/
CreateDomainForest.Lab.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
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
configuration CreateDomainForest
{
param
(
[string[]]
$NodeName ='localhost',
[Parameter(Mandatory)]
[PSCredential]
$AdminCredential,
[Parameter(Mandatory)]
[string]
$DomainName,
[Parameter(Mandatory)]
[PSCredential]
$SafeModeCredential,
[Parameter(Mandatory)]
[string]
$IPAddress,
[Parameter(Mandatory)]
[int]
$SubnetPrefixLength,
[Int]$RetryCount=20,
[Int]$RetryIntervalSec=30
)
# Modules must exist on target pull server
Import-DscResource -Module xActiveDirectory,xNetworking
Import-DscResource -Module xComputerManagement, xStorage
# Create $DomainCredential from $AdminCredential
$DomainUser = "$DomainName\$($AdminCredential.Username)"
$DomainCredential = [PSCredential]::new($DomainUser,$AdminCredential.Password)
Node $AllNodes.NodeName
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyAndMonitor'
}
User AdminUser
{
UserName = $AdminCredential.UserName
Ensure = 'Present'
Password = $AdminCredential
}
Script ChangeCDROMDriveLetter
{
GetScript = {
@{
Result = (Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'").DriveType -ne 5
}
}
SetScript = {
Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'" |
Set-CimInstance -Property @{ DriveLetter = "Z:" }
}
TestScript = {
(Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'").DriveType -ne 5
}
}
xWaitforDisk Disk1
{
DiskNumber = 1
RetryIntervalSec =$RetryIntervalSec
RetryCount = $RetryCount
}
xDisk DataVol
{
DiskNumber = 1
DriveLetter = 'D'
}
WindowsFeature ADDSInstall
{
Ensure = 'Present'
Name = 'AD-Domain-Services'
IncludeAllSubFeature = $true
}
WindowsFeature RSATTools
{
Ensure = 'Present'
Name = 'RSAT-AD-Tools'
IncludeAllSubFeature = $true
}
xIPAddress NewIPAddress
{
IPAddress = $IPAddress
InterfaceAlias = 'Ethernet'
PrefixLength = $SubnetPrefixLength
AddressFamily = 'IPV4'
}
WindowsFeature DNS
{
Ensure = 'Present'
Name = 'DNS'
}
xDnsServerAddress DnsServerAddress
{
Address = '127.0.0.1'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
DependsOn = "[WindowsFeature]DNS"
}
xADDomain NewDscForest
{
DomainName= $DomainName
DomainAdministratorCredential= $AdminCredential
SafemodeAdministratorPassword= $SafeModeCredential
DatabasePath = 'D:\NTDS'
LogPath = 'D:\NTDS'
SysvolPath = 'D:\SYSVOL'
DependsOn=@(
'[WindowsFeature]ADDSInstall',
'[xDnsServerAddress]DnsServerAddress',
'[xDisk]DataVol'
)
}
}
}
$SafeModePW = ConvertTo-SecureString 'InCaseOfFireBreakGlass1!' -AsPlainText -Force
$SafeModeCredential = [PSCredential]::new('Administrator',$SafeModePW)
$AdminPW = ConvertTo-SecureString 'Adminin@tor!' -AsPlainText -Force
$AdminCredential = [PSCredential]::new('Administrator',$AdminPW)
$configData = @{
AllNodes = @(
@{
NodeName = 'localhost';
PSDscAllowPlainTextPassword = $true
}
)
}
$DCParams = @{
AdminCredential = $AdminCredential
DomainName = 'testlab.myorg'
SafeModeCredential = $SafeModeCredential
IPAddress = '192.168.1.250'
SubnetPrefixLength = 24
ConfigurationData = $configData
}
ConfigureFirstDomainController @DCParams
Start-DscConfiguration -Wait -Force -Verbose -path .\ConfigureFirstDomainController -Debug