-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNew-ESXi_ks_conf.ps1
346 lines (328 loc) · 10.9 KB
/
New-ESXi_ks_conf.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
function New-ESXi_ks_conf{
param(
[Parameter(Mandatory=$true,HelpMessage="The kickstart file will be generated for a host with this mac address")]
$Host_macaddress,
[Parameter(Mandatory=$true)]
$DestinationFolder,
[boolean]$Miscellaneous_vmaccepteula = $True,
[ValidateSet('Belgian','Brazilian','Croatian','Czechoslovakian','Danish','Default','Estonian','Finnish','French','German','Greek','Icelandic','Italian','Japanese','Latin American','Norwegian','Polish','Portuguese','Russian','Slovenian','Spanish','Swedish','Swiss French','Swiss German','Turkish','US Dvorak','Ukrainian','United Kingdom')]
$Miscellaneous_keyboard = 'Default',
[boolean]$Miscellaneous_dryrun = $False,
[boolean]$Miscellaneous_reboot = $True ,
[boolean]$Miscellaneous_reboot_noeject = $False,
[Parameter(Mandatory=$true)]
$Miscellaneous_rootpw,
[boolean]$Miscellaneous_rootpw_iscrypted = $False,
[boolean]$Miscellaneous_paranoid = $False,
[boolean]$Miscellaneous_licensekey,
[Parameter(Mandatory=$true,HelpMessage="Select between install, upgrade, or installorupgrade")]
[ValidateSet('install','upgrade','installorupgrade')]
$installorUpgrade_Mode,
[ValidateSet('disk','firstdisk')]
$Install_diskSelection_Mode,
$Install_disk_targetdisk,
$Install_firstdisk_disktypeparameters,
[boolean]$Install_ignoressd,
[boolean]$Install_overwritevsan,
[boolean]$Install_overwritevmfs,
[boolean]$Install_preservevmfs,
[boolean]$Install_novmfsondisk,
[ValidateSet('disk','firstdisk')]
$Upgrade_diskSelection_Mode,
$Upgrade_disk_targetdisk,
$Upgrade_firstdisk_disktypeparameters,
[boolean]$Upgrade_deletecosvmdk = $False,
[ValidateSet('disk','firstdisk')]
$Installorupgrade_diskSelection_Mode,
$Installorupgrade_disk_targetdisk,
$Installorupgrade_firstdisk_disktypeparameters,
[boolean]$Installorupgrade_overwritevsan,
[boolean]$Installorupgrade_overwritevmfs,
[ValidateSet('drives','alldrives','ignoredrives','firstdisk')]
$Clearpart_driveSelection_Mode,
$clearpart_drives_targetdrives,
$clearpart_ignoredrives_targetdrives,
$clearpart_firstdisk_disktypeparameters,
[boolean]$clearpart_overwritevmfs,
[ValidateSet('ondisk','firtdisk')]
$partition_diskSelection_Mode,
$partition_datastorename,
$partition_ondisk_targetdisk,
$partition_onfirstdisk_disktypeparameters,
[ValidateSet('dhcp','static')]
$Network_bootproto_Mode,
$Network_device,
$Network_ip,
$Network_gateway,
$Network_nameserver,
$Network_netmask,
$Network_hostname,
$Network_vlanid,
[boolean]$Network_addvmportgroup
)
process{
$MacAddressNewFormat = $Host_MacAddress -replace ":","-"
$DestinationFilePath = $DestinationFolder + "\" + $MacAddressNewFormat + "_ks.cfg"
If(Test-Path $DestinationFilePath ){
Remove-item $DestinationFilePath -Force
}
$stream1 = [System.IO.StreamWriter] $DestinationFilePath
#Miscellaneous section
if ($Miscellaneous_vmaccepteula){
$ToWrite = '# Accepts the VMware License Agreement (EULA).' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'vmaccepteula' + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
IF($Miscellaneous_keyboard){
$ToWrite = '# Set the keyboard type for the system' + "`n"
$stream1.Write($ToWrite)
$ToWrite = "keyboard '" + $Miscellaneous_keyboard + "'" + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
IF($Miscellaneous_dryrun){
$ToWrite = '# Parse and check the kickstart file, but do not actually do the install.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = "dryrun" + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
if ($Miscellaneous_reboot){
$ToWrite = '# Reboot the machine after the scripted installation is finished.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'reboot'
if($Miscellaneous_reboot_noeject){
$ToWrite = $ToWrite + '--noeject'
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
If($Miscellaneous_rootpw){
$ToWrite = '# Set the root password for the DCUI and Tech Support Mode' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'rootpw'
If($Miscellaneous_rootpw_iscrypted){
$ToWrite = $ToWrite + ' --iscrypted'
}
$ToWrite = $ToWrite + ' ' + $Miscellaneous_rootpw + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
IF($Miscellaneous_paranoid){
$ToWrite = '# Causes warning messages to interrupt the installation. If you omit this command, warning messages are logged.'+ "`n"
$stream1.Write($ToWrite)
$ToWrite = "paranoid" + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
IF($Miscellaneous_licensekey){
$ToWrite = '# Deprecated in ESXi 5.0.x. Supported in ESXi 5.1 and later. Configures licensing. If not included, ESXi installs in evaluation mode' + "`n"
$stream1.Write($ToWrite)
$ToWrite = "serialnum --esx=" + $Miscellaneous_licensekey + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
#Installation or upgrade section
switch($installorUpgrade_Mode){
install {
$ToWrite = '# Specifies that this is a fresh installation. Replaces the deprecated autopart command used for ESXi 4.1 scripted installations. Either the install, upgrade, or installorupgrade command is required to determine which disk to install or upgrade ESXi on.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'install'
switch($Install_diskSelection_Mode){
disk{
$ToWrite = $ToWrite + ' --disk=' + $Install_disk_targetdisk
}
firstdisk{
$ToWrite = $ToWrite + ' --firstdisk'
if($Install_firstdisk_disktypeparameters){
$ToWrite = $ToWrite + '=' + $Install_firstdisk_disktypeparameters
}
If($Install_ignoressd){
$ToWrite = $ToWrite + ' --ignoressd'
}
}
}
if($Install_overwritevsan){
$ToWrite = $ToWrite + ' --overwritevsan'
}
if($Install_overwritevmfs){
$ToWrite = $ToWrite + ' --overwritevmfs'
}
if($Install_preservevmfs){
$ToWrite = $ToWrite + ' --preservevmfs'
}
if($Install_novmfsondisk){
$ToWrite = $ToWrite + ' --novmfsondisk'
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
upgrade {
$ToWrite = '# Specifies that this is a upgrade. Replaces the deprecated autopart command used for ESXi 4.1 scripted installations. One of the commands install, upgrade, or installorupgrade is required to determine which disk to install or upgrade ESXi on.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'upgrade'
switch($Upgrade_diskSelection_Mode){
disk{
$ToWrite = $ToWrite + ' --disk=' + $Upgrade_disk_targetdisk
}
firstdisk{
$ToWrite = $ToWrite + ' --firstdisk'
if($Upgrade_firstdisk_disktypeparameters){
$ToWrite = $ToWrite + '=' + $Upgrade_firstdisk_disktypeparameters
}
}
}
if($Upgrade_deletecosvmdk){
$ToWrite = $ToWrite + ' --deletecosvmdk'
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
installorupgrade {
$ToWrite = '# Either the install, upgrade, or installorupgrade command is required to determine which disk to install or upgrade ESXi on.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'installorupgrade'
switch($Installorupgrade_diskSelection_Mode){
disk{
$ToWrite = $ToWrite + ' --disk=' + $Installorupgrade_disk_targetdisk
}
firstdisk{
$ToWrite = $ToWrite + ' --firstdisk'
if($Installorupgrade_firstdisk_disktypeparameters){
$ToWrite = $ToWrite + '=' + $Installorupgrade_firstdisk_disktypeparameters
}
}
}
if($Installorupgrade_overwritevsan){
$ToWrite = $ToWrite + ' --overwritevsan'
}
if($Installorupgrade_overwritevsan){
$ToWrite = $ToWrite + ' --overwritevmfs'
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
}
#Clearpart section
if($installorUpgrade_Mode -eq "install"){
if($Clearpart_driveSelection_Mode){
$ToWrite = '# Clears any existing partitions on the disk. Requires the install command to be specified. Carefully edit the clearpart command in your existing scripts.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'clearpart'
$stream1.Write($ToWrite)
switch($Clearpart_driveSelection_Mode){
drives{
$ToWrite = $ToWrite + ' --drives=' + $clearpart_drives_targetdrives
}
alldrives{
$ToWrite = $ToWrite + ' --alldrives'
}
ignoredrives{
$ToWrite = $ToWrite + ' --ignoredrives=' + $clearpart_ignoredrives_targetdrives
}
firstdisk{
$ToWrite = $ToWrite + ' --firstdisk'
if($clearpart_firstdisk_disktypeparameters){
$ToWrite = $ToWrite + '=' + $clearpart_firstdisk_disktypeparameters
}
}
}
if(clearpart_overwritevmfs){
$ToWrite = $ToWrite + ' --overwritevmfs'
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
}
#Partition section
if($partition_diskSelection_Mode){
$ToWrite = '# Creates an additional VMFS datastore on the system. Only one datastore per disk can be created. Cannot be used on the same disk as the install command. Only one partition can be specified per disk and it can only be a VMFS partition.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'partition'
$stream1.Write($ToWrite)
switch($partition_diskSelection_Mode){
ondisk{
$ToWrite = $ToWrite + ' --ondisk=' + $partition_ondisk_targetdisk
}
firstdisk{
$ToWrite = $ToWrite + ' --firstdisk'
if($partition_onfirstdisk_disktypeparameters){
$ToWrite = $ToWrite + '=' + $partition_onfirstdisk_disktypeparameters
}
}
}
if($partition_datastorename){
$ToWrite = $ToWrite + ' ' + $partition_datastorename
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
$ToWrite = "`n"
$stream1.Write($ToWrite)
}
#Network section
if($Network_bootproto_Mode){
$ToWrite = '# Specify a network address for the system.' + "`n"
$stream1.Write($ToWrite)
$ToWrite = 'network'
switch($Network_bootproto_Mode){
dhcp{
$ToWrite = $ToWrite+ ' --bootproto=dhcp'
}
static{
$ToWrite = $ToWrite + ' --bootproto=static'
if($Network_ip){
$ToWrite = $ToWrite + ' --ip=' + $Network_ip
}
if($Network_gateway){
$ToWrite = $ToWrite + ' --gateway=' + $Network_gateway
}
if($Network_nameserver){
$ToWrite = $ToWrite + ' --nameserver=' + $Network_nameserver
}
if($Network_netmask){
$ToWrite = $ToWrite + ' --netmask=' + $Network_netmask
}
}
}
if($Network_device){
$ToWrite = $ToWrite + ' --device=' + $Network_device
}
if($Network_hostname){
$ToWrite = $ToWrite + ' --hostname=' + $Network_hostname
}
if($Network_vlanid){
$ToWrite = $ToWrite + ' --vlanid=' + $Network_vlanid
}
if($PSBoundParameters.ContainsKey('Network_addvmportgroup')){
if($Network_addvmportgroup -eq $true){
$ToWrite = $ToWrite + ' --addvmportgroup=1'
}
Else{
$ToWrite = $ToWrite + ' --addvmportgroup=0'
}
}
$ToWrite = $ToWrite + "`n"
$stream1.Write($ToWrite)
}
$stream1.Close()
$stream1 = $Null
}
}