-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurePullServer.Lab.Ps1
176 lines (150 loc) · 5.04 KB
/
ConfigurePullServer.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
166
167
168
169
170
171
172
173
174
175
176
configuration ConfigurePullServer
{
param
(
[string[]]$NodeName = 'localhost',
[ValidateNotNullOrEmpty()]
[string] $certificateThumbPrint,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $RegistrationKey,
[Parameter(Mandatory)]
[PsCredential]
$AdminCredential,
[Parameter(Mandatory)]
[string]
$IPAddress,
[Parameter(Mandatory)]
[int]
$SubnetPrefixLength,
[Parameter(Mandatory)]
[string]
$OUPath,
[Parameter(Mandatory)]
[string]
$DomainName
)
# Modules must exist on target pull server
Import-DSCResource -ModuleName xPSDesiredStateConfiguration
Import-DSCResource –ModuleName PSDesiredStateConfiguration
Import-DscResource -Module xActiveDirectory,xNetworking
Import-DscResource -Module xComputerManagement,xStorage
Node $AllNodes.NodeName
{
LocalConfigurationManager
{
ActionAfterReboot = 'ContinueConfiguration'
ConfigurationMode = 'ApplyAndMonitor'
}
User AdminUser
{
UserName = $AdminCredential.UserName
Ensure = 'Present'
Password = $AdminCredential
}
Script ChangeCDROMDriveLetter
{
GetScript = {
@{
GetScript = $GetScript
SetScript = $SetScript
TestScript = $TestScript
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 = {
$Status = (Get-CimInstance -ClassName Win32_Volume -Filter "DriveLetter = 'D:'").DriveType -ne 5
$Status -eq $True
}
}
xWaitforDisk Disk1
{
DiskNumber = 1
RetryIntervalSec =$RetryIntervalSec
RetryCount = $RetryCount
}
xDisk DataVol
{
DiskNumber = 1
DriveLetter = 'D'
}
xIPAddress NewIPAddress
{
IPAddress = $IPAddress
InterfaceAlias = 'Ethernet'
PrefixLength = $SubnetPrefixLength
AddressFamily = 'IPV4'
}
xDnsServerAddress DnsServerAddress
{
Address = '192.168.1.250'
InterfaceAlias = 'Ethernet'
AddressFamily = 'IPv4'
DependsOn = "[xIPAddress]NewIPAddress"
}
WindowsFeature DSCServiceFeature
{
Ensure = "Present"
Name = "DSC-Service"
}
WindowsFeature IISConsole {
Ensure = "Present"
Name = "Web-Mgmt-Console"
}
xDscWebService PSDSCPullServer
{
Ensure = "Present"
EndpointName = "PSDSCPullServer"
Port = 8080
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer"
CertificateThumbPrint = "AllowUnencryptedTraffic"
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules"
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration"
State = "Started"
DependsOn = "[WindowsFeature]DSCServiceFeature"
UseSecurityBestPractices = $false
}
File RegistrationKeyFile
{
Ensure ='Present'
Type = 'File'
DestinationPath = "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt"
Contents = $RegistrationKey
}
xComputer JoinDomain
{
Name = $NodeName
DomainName = $DomainName
Credential = $AdminCredential
JoinOU = $OUPath
DependsOn = "[xDNSServerAddress]DnsServerAddress"
}
}
}
$RegistrationKey = [guid]::NewGuid()
$AdminPW = ConvertTo-SecureString 'Adminin@tor!' -AsPlainText -Force
$AdminCredential = [PSCredential]::new('testlab\Administrator',$AdminPW)
$configData = @{
AllNodes = @(
@{
NodeName = $env:ComputerName
PSDscAllowPlainTextPassword = $true
}
)
}
$PullSvrParams = @{
RegistrationKey = $RegistrationKey
DomainName = 'testlab.myorg'
AdminCredential = $AdminCredential
IPAddress = '192.168.1.251'
SubnetPrefixLength = 24
OUPath = 'OU=Administrative,OU=Servers,DC=testlab,DC=myorg'
ConfigurationData = $configData
}
# Generate MOF
ConfigurePullServer @PullSvrParams
Start-DscConfiguration -Path .\ConfigurePullServer -Wait -Verbose -Force -Debug