# # vProfiles V1 # By Alan Renouf # http://virtu-al.net # #Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0 # Generated On: 27/06/2009 9:17 PM # Generated By: Alan ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null #endregion #region Generated Form Objects $vProfiles = New-Object System.Windows.Forms.Form $label3 = New-Object System.Windows.Forms.Label $label2 = New-Object System.Windows.Forms.Label $Disconnect = New-Object System.Windows.Forms.Button $Connect = New-Object System.Windows.Forms.Button $OutputWin = New-Object System.Windows.Forms.TextBox $CopyNetwork = New-Object System.Windows.Forms.Button $NewHost = New-Object System.Windows.Forms.ListBox $BaseHost = New-Object System.Windows.Forms.ListBox $label1 = New-Object System.Windows.Forms.Label $VCSRV = New-Object System.Windows.Forms.TextBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $Disconnect_OnClick= { Disconnect-VIServer $ConVISRV -Confirm:$false $Disconnect.Enabled = $false $CopyNetwork.Enabled = $false $OutputWin.Text += "`r`nDisconnect Successful" $vProfiles.Refresh() } $handler_NewHost_SelectedIndexChanged= { #TODO: Place custom script here } $handler_button3_Click= { $OutputWin.Text += "`r`nConnecting to $($Basehost.SelectedItem)" $vProfiles.Refresh() $CBASEHost = Get-VMHost -Name ($Basehost.SelectedItem) $OutputWin.Text += "`r`nConnecting to $($Newhost.SelectedItem)" $vProfiles.Refresh() $CNEWHost = Get-VMHost -Name ($NewHost.SelectedItem) $OutputWin.Text += "`r`nRetrieving Virtual Switches" $vProfiles.Refresh() $CBASEHost | Get-VirtualSwitch | Foreach { If (($CNEWHost | Get-VirtualSwitch -Name $_.Name -ErrorAction SilentlyContinue) -eq $null){ $vSwitch = $_ $OutputWin.Text += "`r`nCreating Virtual Switch $($_.Name)" $vProfiles.Refresh() $NewSwitch = $CNEWHost | New-VirtualSwitch -Name $_.Name -NumPorts $_.NumPorts -Mtu $_.Mtu } $_ | Get-VirtualPortGroup | Foreach { If (($CNEWHost | Get-VirtualPortGroup -Name $_.Name -ErrorAction SilentlyContinue) -eq $null){ $OutputWin.Text += "`r`n..Creating Portgroup $($_.Name) on $($vSwitch.Name)" $vProfiles.Refresh() $NewPortGroup = $CNEWHost | Get-VirtualSwitch -Name $vSwitch | New-VirtualPortGroup -Name $_.Name -VLanId $_.VLanID } } } $OutputWin.Text += "`r`n-- Configuration Completed --" $vProfiles.Refresh() } $handler_label1_Click= { #TODO: Place custom script here } $handler_listBox1_SelectedIndexChanged= { #TODO: Place custom script here } $handler_button1_Click= { If ($VCSRV.Text -eq "") {$OutputWin.Text = "Please Specify a VC Server above"} Else { $OutputWin.Text = "Connecting to $($VCSRV.Text)" $vProfiles.Refresh() $ConVISRV = Connect-VIServer $VCSRV.Text If ($ConVISRV.IsConnected -eq $true) { $OutputWin.Text += "`r`nConnection Successful" $vProfiles.Refresh() $Disconnect.Enabled = $true $CopyNetwork.Enabled = $true Foreach ($EsxHost in (Get-VMHost)) { $BaseHost.Items.Add("$($EsxHost.Name)")|Out-Null $NewHost.Items.Add("$($EsxHost.Name)")|Out-Null } } Else { $OutputWin.Text += "`r`nConnection Un-Successful - Please try again." $vProfiles.Refresh() } } } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $vProfiles.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 563 $System_Drawing_Size.Height = 503 $vProfiles.MaximumSize = $System_Drawing_Size $vProfiles.AutoSize = $True $vProfiles.Text = 'vProfiles' $vProfiles.ShowInTaskbar = $False $vProfiles.MaximizeBox = $False $vProfiles.Name = 'vProfiles' $vProfiles.SizeGripStyle = 2 $vProfiles.ShowIcon = $False $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 563 $System_Drawing_Size.Height = 503 $vProfiles.MinimumSize = $System_Drawing_Size $vProfiles.StartPosition = 1 $vProfiles.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 547 $System_Drawing_Size.Height = 465 $vProfiles.ClientSize = $System_Drawing_Size $label3.TabIndex = 11 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 13 $label3.Size = $System_Drawing_Size $label3.Text = 'Destination:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 271 $System_Drawing_Point.Y = 43 $label3.Location = $System_Drawing_Point $label3.DataBindings.DefaultDataSourceUpdateMode = 0 $label3.Name = 'label3' $label3.add_Click($handler_label3_Click) $vProfiles.Controls.Add($label3) $label2.TabIndex = 10 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 13 $label2.Size = $System_Drawing_Size $label2.Text = 'Source:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 24 $System_Drawing_Point.Y = 43 $label2.Location = $System_Drawing_Point $label2.DataBindings.DefaultDataSourceUpdateMode = 0 $label2.Name = 'label2' $vProfiles.Controls.Add($label2) $Disconnect.TabIndex = 9 $Disconnect.Name = 'Disconnect' $Disconnect.Enabled = $False $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $Disconnect.Size = $System_Drawing_Size $Disconnect.UseVisualStyleBackColor = $True $Disconnect.Text = 'Disconnect' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 442 $System_Drawing_Point.Y = 10 $Disconnect.Location = $System_Drawing_Point $Disconnect.DataBindings.DefaultDataSourceUpdateMode = 0 $Disconnect.add_Click($Disconnect_OnClick) $vProfiles.Controls.Add($Disconnect) $Connect.TabIndex = 8 $Connect.Name = 'Connect' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $Connect.Size = $System_Drawing_Size $Connect.UseVisualStyleBackColor = $True $Connect.Text = 'Connect' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 360 $System_Drawing_Point.Y = 10 $Connect.Location = $System_Drawing_Point $Connect.DataBindings.DefaultDataSourceUpdateMode = 0 $Connect.add_Click($handler_button1_Click) $vProfiles.Controls.Add($Connect) $OutputWin.Multiline = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 491 $System_Drawing_Size.Height = 264 $OutputWin.Size = $System_Drawing_Size $OutputWin.DataBindings.DefaultDataSourceUpdateMode = 0 $OutputWin.AcceptsReturn = $True $OutputWin.ScrollBars = 2 $OutputWin.Name = 'OutputWin' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 24 $System_Drawing_Point.Y = 189 $OutputWin.Location = $System_Drawing_Point $OutputWin.Enabled = $False $OutputWin.TabIndex = 7 $vProfiles.Controls.Add($OutputWin) $CopyNetwork.TabIndex = 6 $CopyNetwork.Name = 'CopyNetwork' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 179 $System_Drawing_Size.Height = 23 $CopyNetwork.Size = $System_Drawing_Size $CopyNetwork.UseVisualStyleBackColor = $True $CopyNetwork.Enabled = $false $CopyNetwork.Text = 'Copy vSwitches and PortGroups' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 175 $System_Drawing_Point.Y = 160 $CopyNetwork.Location = $System_Drawing_Point $CopyNetwork.DataBindings.DefaultDataSourceUpdateMode = 0 $CopyNetwork.add_Click($handler_button3_Click) $vProfiles.Controls.Add($CopyNetwork) $NewHost.FormattingEnabled = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 244 $System_Drawing_Size.Height = 95 $NewHost.Size = $System_Drawing_Size $NewHost.DataBindings.DefaultDataSourceUpdateMode = 0 $NewHost.ScrollAlwaysVisible = $True $NewHost.Name = 'NewHost' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 271 $System_Drawing_Point.Y = 59 $NewHost.Location = $System_Drawing_Point $NewHost.TabIndex = 5 $NewHost.add_SelectedIndexChanged($handler_NewHost_SelectedIndexChanged) $vProfiles.Controls.Add($NewHost) $BaseHost.FormattingEnabled = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 241 $System_Drawing_Size.Height = 95 $BaseHost.Size = $System_Drawing_Size $BaseHost.DataBindings.DefaultDataSourceUpdateMode = 0 $BaseHost.ScrollAlwaysVisible = $True $BaseHost.Name = 'BaseHost' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 24 $System_Drawing_Point.Y = 59 $BaseHost.Location = $System_Drawing_Point $BaseHost.TabIndex = 4 $BaseHost.add_SelectedIndexChanged($handler_listBox1_SelectedIndexChanged) $vProfiles.Controls.Add($BaseHost) $label1.TabIndex = 1 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 86 $System_Drawing_Size.Height = 23 $label1.Size = $System_Drawing_Size $label1.Text = 'Virtual Center:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 34 $System_Drawing_Point.Y = 15 $label1.Location = $System_Drawing_Point $label1.DataBindings.DefaultDataSourceUpdateMode = 0 $label1.Name = 'label1' $label1.add_Click($handler_label1_Click) $vProfiles.Controls.Add($label1) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 228 $System_Drawing_Size.Height = 20 $VCSRV.Size = $System_Drawing_Size $VCSRV.DataBindings.DefaultDataSourceUpdateMode = 0 $VCSRV.Name = 'VCSRV' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 126 $System_Drawing_Point.Y = 12 $VCSRV.Location = $System_Drawing_Point $VCSRV.TabIndex = 0 $vProfiles.Controls.Add($VCSRV) #endregion Generated Form Code #Save the initial state of the form $InitialFormWindowState = $vProfiles.WindowState #Init the OnLoad event to correct the initial state of the form $vProfiles.add_Load($OnLoadForm_StateCorrection) #Show the Form $vProfiles.ShowDialog()| Out-Null } #End Function #Call the Function GenerateForm