Powershell Form: Provision VMs via GUI and set custom values

Written by robdogaz on March 22nd, 2012

If you are like me you are constantly getting requests to build VMs so I developed this form to allow me to quickly provision VMs and set custom values. I hope this helps someone else as it saves me time.

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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
########################################################################
# Code By: Robert Martin
# URL: www.robertwmartin.com
# Used: PrimalForms
########################################################################
 
#----------------------------------------------
#region Application Functions
#----------------------------------------------
 
function OnApplicationLoad {
	#Note: This function runs before the form is created
	#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
	#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
	#Important: Form controls cannot be accessed in this function
	#TODO: Add snapins and custom code to validate the application load
 
	return $true #return true for success or false for failure
}
 
function OnApplicationExit {
	#Note: This function runs after the form is closed
	#TODO: Add custom code to clean up and unload snapins when the application exits
 
	$script:ExitCode = 0 #Set the exit code for the Packager
}
 
#endregion
 
#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function GenerateForm {
 
	#----------------------------------------------
	#region Import Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
	[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	#endregion
 
	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$form1 = New-Object System.Windows.Forms.Form
	$txtVMName = New-Object System.Windows.Forms.TextBox
	$label11 = New-Object System.Windows.Forms.Label
	$btnClose = New-Object System.Windows.Forms.Button
	$txtPassword = New-Object System.Windows.Forms.TextBox
	$label10 = New-Object System.Windows.Forms.Label
	$txtUsername = New-Object System.Windows.Forms.TextBox
	$label9 = New-Object System.Windows.Forms.Label
	$txtVC = New-Object System.Windows.Forms.TextBox
	$label8 = New-Object System.Windows.Forms.Label
	$btnBuild = New-Object System.Windows.Forms.Button
	$cboGuest = New-Object System.Windows.Forms.ComboBox
	$label7 = New-Object System.Windows.Forms.Label
	$cboNetwork = New-Object System.Windows.Forms.ComboBox
	$label6 = New-Object System.Windows.Forms.Label
	$cboCluster = New-Object System.Windows.Forms.ComboBox
	$label5 = New-Object System.Windows.Forms.Label
	$label4 = New-Object System.Windows.Forms.Label
	$cboMem = New-Object System.Windows.Forms.ComboBox
	$cboCPU = New-Object System.Windows.Forms.ComboBox
	$label3 = New-Object System.Windows.Forms.Label
	$txtPurpose = New-Object System.Windows.Forms.TextBox
	$label2 = New-Object System.Windows.Forms.Label
	$txtOwner = New-Object System.Windows.Forms.TextBox
	$label1 = New-Object System.Windows.Forms.Label
	$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
	#endregion Generated Form Objects
 
	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
 
	$FormEvent_Load={
		#TODO: Initialize Form Controls here
 
	}
 
	$handler_btnClose_Click={
	#TODO: Place custom script here
	$form1.Close()
	}
 
	$handler_btnBuild_Click={
	#TODO: Place custom script here
	Add-PSSnapIn vmware.vimautomation.core
	Connect-VIServer $txtVC.Text -User $txtUsername.Text -Password $txtPassword.Text
	# --- Variables
	$owner = $txtOwner.Text
	$purpose = $txtPurpose.Text
	$vmname = $txtVMName.Text
	$numcpu = $cboCPU.Text
	$memvalue = $cboMem.Text
	$diskvalue = 37
	$memMB = [int]$memvalue * 1024
	$diskMB = $diskvalue * 1024
	$passedcluster = $cboCluster.Text
	$nn = $cboNetwork.Text
	$guestType = $cboGuest.Text
 
	switch ($guestType)
	{
 
		"Red Hat Enterprise Linux 5 (64-bit)"
	  	{
			$gi = "rhel5_64Guest";
	  	}
 
		"Red Hat Enterprise Linux 5 (32-bit)"
	  	{
	                     $gi = "rhel5Guest";
	  	}
	  	"Red Hat Enterprise Linux 6 (64-bit)"
	  	{
	  		$gi = "rhel6_64Guest"
		}
		"Red Hat Enterprise Linux 6 (32-bit)"
		{
			$gi = "rhel6Guest"
		}
		"Windows Server 2008 R2 (64-bit)"
		{
			$gi = "windows7Server64Guest"
		}
		"Windows Server 2008 (32-bit)"
		{
			$gi = "winLonghornGuest"
		}
		"Windows Server 2008 (64-bit)"
		{
			$gi = "winLonghorn64Guest"
		}
		"Windows Server 2003 (32-bit)"
		{
			$gi = "winNetStandardGuest"
		}
		"Windows Server 2003 (64-bit)"
		{
			$gi = "winNetStandard64Guest"
		}
		"Windows 7 (32-bit)"
		{
			$gi = "windows7Guest"
		}
		"Windows 7 (64-bit)"
		{
			$gi = "windows7_64Guest"
		}
		"Windows XP Professional (32-bit)"
		{
			$gi = "winXPProGuest"
		}
		"Windows XP Professional (64-bit)"
		{
			$gi = "winXPPro64Guest"
		}
		"Windows Server 2003 R2 (32-bit)"
		{
			$gi = "winNetStandardGuest"
		}
		"Windows Server 2003 R2 (64-bit)"
		{
			$gi = "winNetStandard64Guest"
		}
	}
	# This will go out to your Virtual Center and pull the Cluster to put your new VM in
	$ResPol = (Get-ResourcePool | where {$_.Parent.ToString() -eq "$passedcluster"} | Select Id).Id.ToString()
	# This will find the least busiest host
	$NewHost = (Get-Cluster "$passedcluster" | Get-VMHost | Sort $_.CPuUsageMhz -Descending | Select -First 1).Name.ToString()
	# This will find a Datastore with least used space available to the host selected above
	$ds = (Get-VMhost $NewHost | Get-Datastore | Where { ($_.FreespaceMB -gt '1024') -And ($_.Name -notlike "*Templates*") -And ($_.Name -notlike "*local*")  -And ($_.Name -notlike "*ISO*")} | Sort-Object FreeSpaceMB -descending | Select -First 1).Name.ToString()
 
	# This determines what OS the guest is and if Linux builds it from scratch and if not uses a Template and puts the VM in a Folder called Provisioned VMs
	if  ($guestType -match "Red Hat*")
	{
	#### --- We Build the VM from scratch
	New-VM -name $vmname -VMHost $NewHost -numcpu $numcpu -DiskMB $diskMB -memoryMB $memMB -datastore $ds -guestID $gi -cd -NetworkName "$nn" -Location "ProvisionedVMs"
	}
	ElseIf ($guestType -like "Windows Server 2003 *32-bit*")
	{
	#### --- We Build the VM from Template
	New-VM -Name $vmname -VMHost $NewHost -Template "TEMPLATE - PHX - W2K3 R2 x64 STD" -OSCustomizationSpec "Windows 2003 R2 x64" -datastore $ds -Location "ProvisionedVMs"
	}
	ElseIf ($guestType -like "Windows Server 2003 *64-bit*")
	{
	#### --- We Build the VM from Template
	New-VM -Name $vmname -VMHost $NewHost -Template "TEMPLATE - PHX - W2K3 R2 x32 STD" -OSCustomizationSpec "Windows 2003 R2 x32" -datastore $ds -Location "ProvisionedVMs"
	}
	Else
	{
	#### --- We Build the VM from Template
	New-VM -Name $vmname -VMHost $NewHost -Template "TEMPLATE - PHX - W2K8 R2 STD SP1" -OSCustomizationSpec "Windows 2008 R2" -datastore $ds -Location "ProvisionedVMs"
	}
 
	# We wait for the VM to be created prior to setting custom values
	Start-Sleep 15
 
	# ------- setCustomValue -------
	# We have VC Custom Attribues for Owner and Purpose and we set that info here
 
	$vm = Get-VM $vmname | Get-View
	$vm.setCustomValue("Purpose", $purpose)
	$vm.setCustomValue("Business Owner", $owner)
	$vmConfigSpec  = New-Object VMware.Vim.VirtualMachineConfigSpec
	$vmConfigSpec.annotation = "Owner: $owner`nPurpose: $purpose"
	$vm.ReconfigVM_Task($vmConfigSpec )
 
	# We set the Memory and CPU here after VM is built
	Get-VM $vmname | Set-VM -MemoryMB $memMB -NumCpu $numcpu -Confirm:$false
 
	# Here we follow PCI hardening guidelines here and set them
	$SecurityOptions = @{
	    # Security Harding Guideline VMX01
	    "isolation.tools.diskShrink.disable"="true";
	    "isolation.tools.diskWiper.disable"="true";
	    # Security Harding Guideline VMX02
	    "RemoteDisplay.maxConnections"="1"
	    # Security Harding Guideline VMX11
	    "isolation.tools.connectable.disable"="true";
	    "isolation.tools.edit.disable"="true";
	    # Security Harding Guideline VMX12
	    "vmci0.unrestricted"="FALSE";
	    # Security Harding Guideline VMX20
	    "log.keepOld"="10";
	    "log.rotateSize"="100000"
	    # Security Harding Guideline VMX21
	    "tools.setInfo.sizeLimit"="1048576";
	    # Security Harding Guideline VMX30
	    "guest.command.enabled"="FALSE";
	    # Security Harding Guideline VMX31
	    "tools.guestlib.enableHostInfo"="FALSE"
	}
 
	$SecurityConfigurationSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
 
	Foreach ($SecurityOption in $SecurityOptions.GetEnumerator()) {
	    $SecurityOptionValue = New-Object VMware.Vim.optionvalue
	    $SecurityOptionValue.Key = $SecurityOption.Key
	    $SecurityOptionValue.Value = $SecurityOption.Value
	    $SecurityConfigurationSpec.extraconfig +=  $SecurityOptionValue
	}
	$VM.ReconfigVM_Task($SecurityConfigurationSpec)
	Write  "$($VM.Name) - changed"
 
	# In our company we let the Linux team load there OS via scripts so we don't start it
	if  ($guestType -match "Red Hat*")
	{
	}
	Else
	{
	# Otherwise if it is Windows we start the VM and let VMware finish configuring it
	Start-VM -VM $vmname
	}
	}
 
	#----------------------------------------------
	# Generated Events
	#----------------------------------------------
 
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$form1.WindowState = $InitialFormWindowState
	}
 
	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# form1
	#
	$form1.Controls.Add($txtVMName)
	$form1.Controls.Add($label11)
	$form1.Controls.Add($btnClose)
	$form1.Controls.Add($txtPassword)
	$form1.Controls.Add($label10)
	$form1.Controls.Add($txtUsername)
	$form1.Controls.Add($label9)
	$form1.Controls.Add($txtVC)
	$form1.Controls.Add($label8)
	$form1.Controls.Add($btnBuild)
	$form1.Controls.Add($cboGuest)
	$form1.Controls.Add($label7)
	$form1.Controls.Add($cboNetwork)
	$form1.Controls.Add($label6)
	$form1.Controls.Add($cboCluster)
	$form1.Controls.Add($label5)
	$form1.Controls.Add($label4)
	$form1.Controls.Add($cboMem)
	$form1.Controls.Add($cboCPU)
	$form1.Controls.Add($label3)
	$form1.Controls.Add($txtPurpose)
	$form1.Controls.Add($label2)
	$form1.Controls.Add($txtOwner)
	$form1.Controls.Add($label1)
	$form1.ClientSize = New-Object System.Drawing.Size(486,372)
	$form1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$form1.Name = "form1"
	$form1.Text = "New VM Build Form"
	$form1.add_Load($FormEvent_Load)
	#
	# txtVMName
	#
	$txtVMName.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtVMName.Location = New-Object System.Drawing.Point(146,337)
	$txtVMName.Name = "txtVMName"
	$txtVMName.Size = New-Object System.Drawing.Size(133,20)
	$txtVMName.TabIndex = 20
	#
	# label11
	#
	$label11.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label11.Location = New-Object System.Drawing.Point(13,337)
	$label11.Name = "label11"
	$label11.Size = New-Object System.Drawing.Size(100,23)
	$label11.TabIndex = 19
	$label11.Text = "VM Name"
	#
	# btnClose
	#
	$btnClose.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$btnClose.Location = New-Object System.Drawing.Point(389,337)
	$btnClose.Name = "btnClose"
	$btnClose.Size = New-Object System.Drawing.Size(75,23)
	$btnClose.TabIndex = 18
	$btnClose.Text = "Close"
	$btnClose.UseVisualStyleBackColor = $True
	$btnClose.add_Click($handler_btnClose_Click)
	#
	# txtPassword
	#
	$txtPassword.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtPassword.Location = New-Object System.Drawing.Point(146,310)
	$txtPassword.Name = "txtPassword"
	$txtPassword.PasswordChar = '*'
	$txtPassword.Size = New-Object System.Drawing.Size(133,20)
	$txtPassword.TabIndex = 17
	$txtPassword.UseSystemPasswordChar = $True
	#
	# label10
	#
	$label10.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label10.Location = New-Object System.Drawing.Point(13,310)
	$label10.Name = "label10"
	$label10.Size = New-Object System.Drawing.Size(100,23)
	$label10.TabIndex = 16
	$label10.Text = "Password"
	#
	# txtUsername
	#
	$txtUsername.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtUsername.Location = New-Object System.Drawing.Point(146,283)
	$txtUsername.Name = "txtUsername"
	$txtUsername.Size = New-Object System.Drawing.Size(133,20)
	$txtUsername.TabIndex = 15
	#
	# label9
	#
	$label9.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label9.Location = New-Object System.Drawing.Point(13,283)
	$label9.Name = "label9"
	$label9.Size = New-Object System.Drawing.Size(100,23)
	$label9.TabIndex = 14
	$label9.Text = "User"
	#
	# txtVC
	#
	$txtVC.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtVC.Location = New-Object System.Drawing.Point(146,256)
	$txtVC.Name = "txtVC"
	$txtVC.Size = New-Object System.Drawing.Size(259,20)
	$txtVC.TabIndex = 13
	$txtVC.Text = "vcenter.domain.local"
	#
	# label8
	#
	$label8.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label8.Location = New-Object System.Drawing.Point(13,256)
	$label8.Name = "label8"
	$label8.Size = New-Object System.Drawing.Size(100,23)
	$label8.TabIndex = 12
	$label8.Text = "Virtual Center"
	#
	# btnBuild
	#
	$btnBuild.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$btnBuild.Location = New-Object System.Drawing.Point(307,337)
	$btnBuild.Name = "btnBuild"
	$btnBuild.Size = New-Object System.Drawing.Size(75,23)
	$btnBuild.TabIndex = 11
	$btnBuild.Text = "Build VM"
	$btnBuild.UseVisualStyleBackColor = $True
	$btnBuild.add_Click($handler_btnBuild_Click)
	#
	# cboGuest
	#
	$cboGuest.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$cboGuest.FormattingEnabled = $True
	[void]$cboGuest.Items.Add("Windows Server 2008 R2 (64-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2008 (32-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2008 (64-bit)")
	[void]$cboGuest.Items.Add("Windows 7 (32-bit)")
	[void]$cboGuest.Items.Add("Windows 7 (64-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2003 R2 (32-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2003 R2 (64-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2003 (32-bit)")
	[void]$cboGuest.Items.Add("Windows Server 2003 (64-bit)")
	[void]$cboGuest.Items.Add("Windows XP Professional (32-bit)")
	[void]$cboGuest.Items.Add("Windows XP Professional (64-bit)")
	[void]$cboGuest.Items.Add("Red Hat Enterprise Linux 6 (32-bit)")
	[void]$cboGuest.Items.Add("Red Hat Enterprise Linux 6 (64-bit)")
	[void]$cboGuest.Items.Add("Red Hat Enterprise Linux 5 (32-bit)")
	[void]$cboGuest.Items.Add("Red Hat Enterprise Linux 5 (64-bit)")
	$cboGuest.Location = New-Object System.Drawing.Point(146,230)
	$cboGuest.Name = "cboGuest"
	$cboGuest.Size = New-Object System.Drawing.Size(296,21)
	$cboGuest.TabIndex = 10
	#
	# label7
	#
	$label7.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label7.Location = New-Object System.Drawing.Point(13,229)
	$label7.Name = "label7"
	$label7.Size = New-Object System.Drawing.Size(100,23)
	$label7.TabIndex = 9
	$label7.Text = "Guest"
	#
	# cboNetwork
	#
	$cboNetwork.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$cboNetwork.FormattingEnabled = $True
	[void]$cboNetwork.Items.Add("Enterprise Network")
	[void]$cboNetwork.Items.Add("Backup Network")
	[void]$cboNetwork.Items.Add("Add More Network here as they are listed in VC")
	$cboNetwork.Location = New-Object System.Drawing.Point(146,202)
	$cboNetwork.Name = "cboNetwork"
	$cboNetwork.Size = New-Object System.Drawing.Size(296,21)
	$cboNetwork.TabIndex = 8
	#
	# label6
	#
	$label6.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label6.Location = New-Object System.Drawing.Point(13,202)
	$label6.Name = "label6"
	$label6.Size = New-Object System.Drawing.Size(100,23)
	$label6.TabIndex = 7
	$label6.Text = "Network"
	#
	# cboCluster
	#
	$cboCluster.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$cboCluster.FormattingEnabled = $True
	[void]$cboCluster.Items.Add("PHX - Dev")
	[void]$cboCluster.Items.Add("PHX - Production")
	[void]$cboCluster.Items.Add("PHX - QA")
	[void]$cboCluster.Items.Add("Add More clusters here as they are listed in VC")
	$cboCluster.Location = New-Object System.Drawing.Point(146,175)
	$cboCluster.Name = "cboCluster"
	$cboCluster.Size = New-Object System.Drawing.Size(296,21)
	$cboCluster.TabIndex = 6
	#
	# label5
	#
	$label5.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label5.Location = New-Object System.Drawing.Point(13,175)
	$label5.Name = "label5"
	$label5.Size = New-Object System.Drawing.Size(100,23)
	$label5.TabIndex = 5
	$label5.Text = "Cluster"
	#
	# label4
	#
	$label4.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label4.Location = New-Object System.Drawing.Point(13,148)
	$label4.Name = "label4"
	$label4.Size = New-Object System.Drawing.Size(100,23)
	$label4.TabIndex = 4
	$label4.Text = "Memory"
	#
	# cboMem
	#
	$cboMem.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$cboMem.FormattingEnabled = $True
	[void]$cboMem.Items.Add("1")
	[void]$cboMem.Items.Add("2")
	[void]$cboMem.Items.Add("3")
	[void]$cboMem.Items.Add("4")
	[void]$cboMem.Items.Add("5")
	[void]$cboMem.Items.Add("6")
	[void]$cboMem.Items.Add("7")
	[void]$cboMem.Items.Add("8")
	$cboMem.Location = New-Object System.Drawing.Point(146,148)
	$cboMem.Name = "cboMem"
	$cboMem.Size = New-Object System.Drawing.Size(121,21)
	$cboMem.TabIndex = 3
	#
	# cboCPU
	#
	$cboCPU.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$cboCPU.FormattingEnabled = $True
	[void]$cboCPU.Items.Add("1")
	[void]$cboCPU.Items.Add("2")
	[void]$cboCPU.Items.Add("3")
	[void]$cboCPU.Items.Add("4")
	[void]$cboCPU.Items.Add("5")
	[void]$cboCPU.Items.Add("6")
	[void]$cboCPU.Items.Add("7")
	[void]$cboCPU.Items.Add("8")
	$cboCPU.Location = New-Object System.Drawing.Point(146,120)
	$cboCPU.Name = "cboCPU"
	$cboCPU.Size = New-Object System.Drawing.Size(121,21)
	$cboCPU.TabIndex = 2
	#
	# label3
	#
	$label3.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label3.Location = New-Object System.Drawing.Point(13,119)
	$label3.Name = "label3"
	$label3.Size = New-Object System.Drawing.Size(100,23)
	$label3.TabIndex = 3
	$label3.Text = "Number of CPUs"
	#
	# txtPurpose
	#
	$txtPurpose.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtPurpose.Location = New-Object System.Drawing.Point(146,40)
	$txtPurpose.Multiline = $True
	$txtPurpose.Name = "txtPurpose"
	$txtPurpose.ScrollBars = [System.Windows.Forms.ScrollBars]::Vertical
	$txtPurpose.Size = New-Object System.Drawing.Size(296,69)
	$txtPurpose.TabIndex = 1
	#
	# label2
	#
	$label2.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label2.Location = New-Object System.Drawing.Point(13,40)
	$label2.Name = "label2"
	$label2.Size = New-Object System.Drawing.Size(100,23)
	$label2.TabIndex = 2
	$label2.Text = "Purpose"
	#
	# txtOwner
	#
	$txtOwner.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$txtOwner.Location = New-Object System.Drawing.Point(146,13)
	$txtOwner.Name = "txtOwner"
	$txtOwner.Size = New-Object System.Drawing.Size(296,20)
	$txtOwner.TabIndex = 0
	#
	# label1
	#
	$label1.DataBindings.DefaultDataSourceUpdateMode = [System.Windows.Forms.DataSourceUpdateMode]::OnValidation
	$label1.Location = New-Object System.Drawing.Point(13,13)
	$label1.Name = "label1"
	$label1.Size = New-Object System.Drawing.Size(100,23)
	$label1.TabIndex = 0
	$label1.Text = "Business Owner(s)"
	#endregion Generated Form Code
 
	#----------------------------------------------
 
	#Save the initial state of the form
	$InitialFormWindowState = $form1.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$form1.add_Load($Form_StateCorrection_Load)
	#Show the Form
	return $form1.ShowDialog()
 
} #End Function
 
#Call OnApplicationLoad to initialize
if(OnApplicationLoad -eq $true)
{
	#Create the form
	GenerateForm | Out-Null
	#Perform cleanup
	OnApplicationExit
}
This entry was posted on Thursday, March 22nd, 2012 at 4:46 am and is filed under PowerCLI, VMware. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Powershell Form: Provision VMs via GUI and set custom values”

  1. Meghan Lauder Says:

    Hi there,
    Thank you for the great well written post.
    Where is your RSS Feed?
    I would love to subscribe to it so I don’t miss any updates.
    Excellent Blog by the way.
    Well done

  2. Robert Says:

    http://twitter.com/#!/robert_w_martin

  3. Robert Says:

    or
    http://www.robertwmartin.com/?feed=rss2

Leave a Reply