-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoWDS.ps1
270 lines (201 loc) · 8.61 KB
/
autoWDS.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Banner
function banner {
$banner = @()
$banner += ''
$banner += ' _ __ _______ _____'
$banner += ' | | \ \ / / __ \ / ____|'
$banner += ' __ _ _ _| |_ __\ \ /\ / /| | | | (___'
$banner += ' / _` | | | | __/ _ \ \/ \/ / | | | |\___ \'
$banner += '| (_| | |_| | || (_) \ /\ / | |__| |____) | [By Adrian Lujan Munoz (aka clhore)]'
$banner += ' \__,_|\__,_|\__\___/ \/ \/ |_____/|_____/'
$banner += ''
$banner | foreach-object {
Write-Host $_ -ForegroundColor (Get-Random -Input @('Cyan','Green','gray','white', 'yellow'))
}
}
# comprobar servidor NTP
# $ w32tm /dumpreg /subkey:parameters
# sincronizar relog con la rediris (en este caso son los servidores de Valencia)
# $ w32tm /config /syncfromflags:manual /manualpeerlist:"EB-Valencia1.rediris.es EB-Valencia0.rediris.es" /update
# Configura los parametros de la interfaz
$Global:ifIndex = 2 # Revisalo con el comando Get-NetAdapter
# Configuracion de la red
$Global:ipParams = @{
InterfaceIndex = $ifIndex
IPAddress = "192.168.1.170" # Ip fija a asignar al equipo
DefaultGateway = "192.168.1.1" # Puerta de enlace
PrefixLength = 24 # Mascara
AddressFamily = "IPv4"
}
$Global:dnsParams = @{
InterfaceIndex = $ifIndex
ServerAddresses = ("8.8.8.8","8.8.4.4")
}
# Configuracion del DC
$Global:namePc = 'LUJAN'
$Global:domainName = 'OSORNO.IES'
# Configuracion DHCP
$Global:dhcpParams = @{
Name = "IPs clientes"
StartRange = "192.168.1.200"
EndRange = "192.168.1.220"
SubnetMask = "255.255.255.0"
}
# Configuracion WDS
$Global:routeRemoteInstall = "E:\RemoteInstall"
$Global:fileBoot = "D:\sources\boot.wim"
$Global:fileInstall = "D:\sources\install.wim"
$Global:imageName = "Windows 7 PROFESSIONAL" # Get-WindowsImage -imagePath "D:\sources\install.wim" | select ImageName
$Global:groupName = "win7"
# Panel de ayuda
function helpPanel {
banner
$textColor = 'Green'
$textColor2 = 'yellow'
Write-Output ''
Write-Host ' 1. Importe los modulos:' -Foreground $textColor
Write-Output ''
Write-Host ' - Import-Module .\autoWDS.ps1' -Foreground $textColor2
Write-Output ''
Write-Host ' 2. Ejecute el comando redConfig' -Foreground $textColor
Write-Output ''
Write-Host " 3. Ejecuta el comando namePc_and_domainServicesInstallation_1" -Foreground $textColor
Write-Output ''
Write-Host " 4. Tras el primer reinicio ejecute el comando domainServicesInstallation_2" -Foreground $textColor
Write-Output ''
Write-Host " - En este punto equipo deberia quedar configurado como DC. " -Foreground $textColor2
Write-Output ''
Write-Host " 5. Ejecute el comando DHCP_WDS_Installation" -Foreground $textColor
Write-Output ''
Write-Host " - Con este comando se instalara el rol de DHCP y WDS" -Foreground $textColor2
Write-Output ''
Write-Host " - Ademas de configurar un ambito con los parametros configurados anteriormente" -Foreground $textColor2
Write-Output ''
Write-Host " 6. Ahora ya puede dirigirse a Servicios de implementation de Windows" -Foreground $textColor
Write-Output ''
Write-Host " - Inserte un archivo intsall.wim" -Foreground $textColor2
Write-Output ''
Write-Host " - Inserte un archivo boot.wim" -Foreground $textColor2
Write-Output ''
Write-Host " 7. Si quieres configurar el servicio WDS haciendo uso de este scrip ejecute el comado configWDS" -Foreground $textColor
Write-Output ''
Write-Host " - Insertara el boot.wim que este definido en el script" -Foreground $textColor2
Write-Output ''
Write-Host " - Inserte la version del install.wim que este definido en el script" -Foreground $textColor2
Write-Output ''
Write-Host " - Ademas de agregar la imagen al grupo definido" -Foreground $textColor2
Write-Output ''
}
function redConfig {
New-NetIPAddress @ipParams
Set-DnsClientServerAddress @dnsParams
}
function namePc_and_domainServicesInstallation_1 {
banner
Write-Output ''
Write-Host "[*] Instalando los servicios de dominio y configurando el dominio" -ForegroundColor "yellow"
Write-Output ''
Add-WindowsFeature RSAT-ADDS
Install-WindowsFeature -Name AD-Domain-Services
Import-Module ServerManager
Import-Module ADDSDeployment
Write-Output ''
Write-Host "[*] Cambiando el nombre de equipo a $namePc" -ForegroundColor "yellow"
Write-Output ''
Rename-Computer -NewName $namePc
Write-Output ''
Write-Host "[V] Nombre de equipo cambiado exitosamente, el quipo se va a reiniciar" -ForegroundColor "green"
Write-Output ''
Start-Sleep -Seconds 5
Restart-Computer
}
function domainServicesInstallation_2 {
Write-Output ''
Write-Host "[*] A continuacion, deberas proporcionar la password del usuario Administrador del dominio" -ForegroundColor "yellow"
Write-Output ''
Try {
$confAD = @{
CreateDnsDelegation = $false
DatabasePath = "C:\\Windows\\NTDS"
DomainMode = "7"
DomainName = $domainName
DomainNetbiosName = $domainName | %{ $_.Split('.')[0]; }
ForestMode = "7"
InstallDns = $true
LogPath = "C:\\Windows\\NTDS"
NoRebootOnCompletion = $false
SysvolPath = "C:\\Windows\\SYSVOL"
Force = $true
}
Install-ADDSForest @confAD
} Catch { Restart-Computer }
Write-Output ''
Write-Host "[!] Se va a reiniciar el equipo. Deberas iniciar sesion con el usuario Administrador del dominio" -ForegroundColor "yellow"
Write-Output ''
}
function DHCP_WDS_Installation {
banner
Write-Output ''
Write-Host "[*] Intalando rol DHCP" -ForegroundColor "yellow"
Write-Output ''
Try {
Install-WindowsFeature -name "DHCP" -IncludeManagementTools
Write-Output ''
Write-Host "[*] Configurando DHCP" -ForegroundColor "green"
Write-Output ''
Add-DhcpServerv4Scope @dhcpParams
Set-DhcpServerv4OptionValue -DNSServer $ipParams.IPAddress -Router $ipParams.DefaultGateway
Start-Sleep -Seconds 2
Write-Output ''
Write-Host "[*] Reiniciando el servicio DHCP" -ForegroundColor "green"
Write-Output ''
Restart-service dhcpserver
} Catch {
Write-Output ''
Write-Host "[!] Error instalando el rol DHCP" -ForegroundColor "red"
Write-Output ''
}
Start-Sleep -Seconds 2
Write-Output ''
Write-Host "[*] Intalando rol WDS" -ForegroundColor "yellow"
Write-Output ''
Try {
Install-WindowsFeature -name "WDS" -IncludeManagementTools
Start-Sleep -Seconds 2
} Catch {
Write-Output ''
Write-Host "[!] Error instalando el rol WDS" -ForegroundColor "red"
Write-Output ''
}
Write-Output ''
Write-Host "[!] Se va a reiniciar el equipo." -ForegroundColor "red"
Write-Output ''
Start-Sleep -Seconds 5
Restart-Computer
}
function configWDS {
Write-Output ''
Write-Host "[*] Configurando el servicio WDS" -ForegroundColor "green"
Write-Output ''
wdsutil /initialize-server /remInst:"$routeRemoteInstall" | select -last 1
Write-Output ''
Write-Host "[*] Configurando archivo boot.wim" -ForegroundColor "yellow"
Write-Output ''
Import-WdsBootImage -Path $fileBoot -ErrorAction SilentlyContinue
Write-Output ''
Write-Host "[*] Configurando install.wim" -ForegroundColor "yellow"
Write-Output ''
Write-Output ''
Write-Host "[*] Creando grupo de imagenes" -ForegroundColor "yellow"
New-WdsInstallImageGroup -name $groupName
Write-Output ''
Write-Host "[*] Insertando imagen" -ForegroundColor "yellow"
Import-WdsInstallImage -ImageGroup $groupName -Path $fileInstall -ImageName $imageName -ErrorAction SilentlyContinue
Write-Output ''
Write-Host "NameImagen : $imageName" -ForegroundColor "white"
Write-Host "NameGroup : $groupName" -ForegroundColor "white"
Write-Output ''
Write-Host "[*] Iniciando el servidor WDS" -ForegroundColor "yellow"
Write-Output ''
Start-Service -Name WDSServer
}