Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
- $defaultvCenter = "vcenter"
- $viServer = $null
- #Generated Form Function
- function GenerateForm {
- ########################################################################
- # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0
- # Generated On: 10/24/2013 11:00 AM
- ########################################################################
- #region Import the Assemblies
- [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
- [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
- #endregion
- #region Generated Form Objects
- $form1 = New-Object System.Windows.Forms.Form
- $hostnameTextbox = New-Object System.Windows.Forms.TextBox
- $connectButton = New-Object System.Windows.Forms.Button
- $exitButton = New-Object System.Windows.Forms.Button
- $openButton = New-Object System.Windows.Forms.Button
- $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
- #endregion Generated Form Objects
- #----------------------------------------------
- #Generated Event Script Blocks
- #----------------------------------------------
- #Provide Custom Code for events specified in PrimalForms.
- $exitButton_OnClick=
- {
- $global:viServer = Disconnect-VIServer -server $global:viServer.name -Force -Confirm:$false
- $form1.Close()
- }
- $connectButton_OnClick=
- {
- $vCenter = $hostnameTextbox.Text
- $global:viServer.IsConnected
- if ($viServer.IsConnected) {
- Write-Host "Disconnecting from $vCenter"
- $global:viServer = Disconnect-VIServer -server $global:viServer.name -Force -Confirm:$false
- $openButton.Enabled = $false
- }
- $global:viServer = Connect-VIServer $vCenter -ErrorAction SilentlyContinue
- if ($global:viServer.IsConnected) {
- Write-Host "Successfully connected to $vCenter"
- $openButton.Enabled = $true
- }
- else {
- [System.Windows.Forms.MessageBox]::Show("Failed to connect to vCenter server '$vCenter'", "Connection Failed")
- $global:viServer = Disconnect-VIServer -server $global:viServer.name -Force -Confirm:$false
- $openButton.Enabled = $false
- }
- }
- $openButton_OnClick=
- {
- $Selection = Get-VM | Out-GridView -OutputMode Multiple
- $Selection | Foreach { Open-VMConsoleWindow $_ }
- }
- $OnLoadForm_StateCorrection=
- {#Correct the initial state of the form to prevent the .Net maximized form issue
- $form1.WindowState = $InitialFormWindowState
- }
- #----------------------------------------------
- #region Generated Form Code
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 108
- $System_Drawing_Size.Width = 284
- $form1.ClientSize = $System_Drawing_Size
- $form1.DataBindings.DefaultDataSourceUpdateMode = 0
- $form1.Name = "form1"
- $form1.Text = "VM Console Viewer"
- $hostnameTextbox.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 12
- $System_Drawing_Point.Y = 16
- $hostnameTextbox.Location = $System_Drawing_Point
- $hostnameTextbox.Name = "hostnameTextbox"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 20
- $System_Drawing_Size.Width = 156
- $hostnameTextbox.Size = $System_Drawing_Size
- $hostnameTextbox.TabIndex = 3
- $hostnameTextbox.Text = $defaultvCenter
- $form1.Controls.Add($hostnameTextbox)
- $connectButton.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 174
- $System_Drawing_Point.Y = 14
- $connectButton.Location = $System_Drawing_Point
- $connectButton.Name = "connectButton"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 98
- $connectButton.Size = $System_Drawing_Size
- $connectButton.TabIndex = 2
- $connectButton.Text = "Connect"
- $connectButton.UseVisualStyleBackColor = $True
- $connectButton.add_Click($connectButton_OnClick)
- $form1.Controls.Add($connectButton)
- $exitButton.DataBindings.DefaultDataSourceUpdateMode = 0
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 12
- $System_Drawing_Point.Y = 72
- $exitButton.Location = $System_Drawing_Point
- $exitButton.Name = "exitButton"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 260
- $exitButton.Size = $System_Drawing_Size
- $exitButton.TabIndex = 1
- $exitButton.Text = "Quit"
- $exitButton.UseVisualStyleBackColor = $True
- $exitButton.add_Click($exitButton_OnClick)
- $form1.Controls.Add($exitButton)
- $openButton.DataBindings.DefaultDataSourceUpdateMode = 0
- $openButton.Enabled = $False
- $System_Drawing_Point = New-Object System.Drawing.Point
- $System_Drawing_Point.X = 12
- $System_Drawing_Point.Y = 43
- $openButton.Location = $System_Drawing_Point
- $openButton.Name = "openButton"
- $System_Drawing_Size = New-Object System.Drawing.Size
- $System_Drawing_Size.Height = 23
- $System_Drawing_Size.Width = 260
- $openButton.Size = $System_Drawing_Size
- $openButton.TabIndex = 0
- $openButton.Text = "Open VM Consoles"
- $openButton.UseVisualStyleBackColor = $True
- $openButton.add_Click($openButton_OnClick)
- $form1.Controls.Add($openButton)
- #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($OnLoadForm_StateCorrection)
- #Show the Form
- $form1.ShowDialog()| Out-Null
- } #End Function
- #Call the Function
- GenerateForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement