Advertisement
Guest User

Event-O-Matic

a guest
Mar 29th, 2017
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function GenerateForm {
  3.  
  4.     #region Helper functions
  5.     function Update-EventList {
  6.         $tgtSearch = ""
  7.         if($SearchText.Text){
  8.             $tgtSearch = $SearchText.Text
  9.         }
  10.  
  11.         $EventList.BeginUpdate()
  12.         $EventList.Items.Clear()
  13.         $script:eventTab.GetEnumerator()| Sort-Object -Property Key |
  14.         where {$_.Key -match $tgtSearch -or $_.Value.FullFormat -match $tgtSearch} | %{
  15.             if($EventDescriptionRadio.Checked){
  16.                 $EventList.Items.Add($_.Value.Description)
  17.             }
  18.             else {
  19.                 $EventList.Items.Add($_.Key)}
  20.         }
  21.         $EventList.EndUpdate()
  22.     }
  23. #endregion
  24.  
  25.     ########################################################################
  26.     # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0
  27.     # Generated On: 7/14/2013 3:52 PM
  28.     # Generated By: Luc Dekens
  29.     ########################################################################
  30.  
  31.     #region Import the Assemblies
  32.     [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
  33.     [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  34.  
  35. #endregion
  36.  
  37.     #region Generated Form Objects
  38.     $EventOMaticForm = New-Object System.Windows.Forms.Form
  39.     $EventDescriptionRadio = New-Object System.Windows.Forms.RadioButton
  40.     $vSphereServer = New-Object System.Windows.Forms.ComboBox
  41.     $EventNameRadio = New-Object System.Windows.Forms.RadioButton
  42.     $vsphereinfo = New-Object System.Windows.Forms.Label
  43.     $EventSelectedNumber = New-Object System.Windows.Forms.Label
  44.     $groupBox1 = New-Object System.Windows.Forms.GroupBox
  45.     $EventNumber = New-Object System.Windows.Forms.Label
  46.     $Search = New-Object System.Windows.Forms.Button
  47.     $SearchText = New-Object System.Windows.Forms.TextBox
  48.     $EventClear = New-Object System.Windows.Forms.Button
  49.     $FinishButton = New-Object System.Windows.Forms.Button
  50.     $EventPlusRadio = New-Object System.Windows.Forms.CheckBox
  51.     $GenerateCodeButton = New-Object System.Windows.Forms.Button
  52.     $SelectedEventList = New-Object System.Windows.Forms.ListBox
  53.     $label4 = New-Object System.Windows.Forms.Label
  54.     $EventList = New-Object System.Windows.Forms.ListBox
  55.     $label2 = New-Object System.Windows.Forms.Label
  56.     $ConnectButton = New-Object System.Windows.Forms.Button
  57.     $label1 = New-Object System.Windows.Forms.Label
  58.     $EventToolTip = New-Object System.Windows.Forms.ToolTip
  59.     $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  60. #endregion
  61.  
  62.     #region Generated Event Script Blocks
  63.     #----------------------------------------------
  64.     #Generated Event Script Blocks
  65.     #----------------------------------------------
  66.     $FinishClicked = {
  67.         $EventOMaticForm.Close()
  68.     }
  69.  
  70.     $SearchTextFocusOn = {
  71.         $EventOMaticForm.AcceptButton = $Search
  72.     }
  73.  
  74.     $SearchTextFocusOff = {
  75.         $EventOMaticForm.AcceptButton = $FinishButton
  76.     }
  77.  
  78.     $EventMouseMove = {
  79.         param(
  80.             $obj,
  81.             [System.Windows.Forms.MouseEventArgs]$mEventArgs
  82.         )
  83.  
  84.         $listIndex = $obj.IndexFromPoint($mEventArgs.Location)
  85.         if($listIndex -ge 0 -and $listIndex -lt $obj.Items.Count){
  86.             if($EventToolTip.GetToolTip($obj) -ne $script:eventTab[$obj.Items[$listIndex]].FullFormat){
  87.                 $EventToolTip.SetToolTip($obj,$script:eventTab[$obj.Items[$listIndex]].FullFormat)
  88.             }
  89.         }
  90.         else{
  91.             $EventToolTip.Hide($obj)
  92.         }
  93.     }
  94.  
  95.     $EventRadioChanged = {
  96.         Update-EventList
  97.     }
  98.  
  99.     $EventClicked = {
  100.         param(
  101.             $obj,
  102.             [System.Windows.Forms.MouseEventArgs]$mEventArgs
  103.         )
  104.  
  105.         $obj.BeginUpdate()
  106.         if($obj -eq $EventList){
  107.             if($EventDescriptionRadio.Checked){
  108.                 $selectedEvent = $script:eventTab.GetEnumerator() | Sort-Object -Property Key |
  109.                 where {$EventList.SelectedItem -eq $_.Value.Description}
  110.             }
  111.             else {
  112.                 $selectedEvent = $script:eventTab.GetEnumerator() | Sort-Object -Property Key |
  113.                 where {$EventList.SelectedItem -eq $_.Key}
  114.             }
  115.             if(!$SelectedEventList.Items.Contains($selectedEvent.Key)){
  116.                 $SelectedEventList.Items.Add($selectedEvent.Key)
  117.             }
  118.  
  119.         }
  120.         else{
  121.             $SelectedEventList.Items.Remove($SelectedEventList.SelectedItem)
  122.         }
  123.         $obj.EndUpdate()
  124.         $EventSelectedNumber.Text = "$($SelectedEventList.Items.Count)"
  125.         #       }
  126.     }
  127.  
  128.     $SearchClicked = {
  129.         $EventList.BeginUpdate()
  130.  
  131.         $EventList.Items.Clear()
  132.         $script:eventTab.GetEnumerator()|
  133.         where {$_.Key -match $SearchText.Text -or $_.Value.FullFormat -match $SearchText.Text} | %{
  134.             if($EventDescriptionRadio.Checked){
  135.                 $EventList.Items.Add($script:eventTab[$_.Key].FullFormat)
  136.             }
  137.             else {
  138.                 $EventList.Items.Add($_.Key)
  139.             }
  140.         }
  141.         $EventList.EndUpdate()
  142.         $EventNumber.Text = "$($EventList.Items.Count)"
  143.     }
  144.  
  145.     $SearchTextChanged = {
  146.         if(!$SearchText.Text){
  147.             $EventList.BeginUpdate()
  148.             $EventList.Items.Clear()
  149.             if($EventDescriptionRadio.Checked){
  150.                 $script:eventTab.Keys | %{
  151.                     $EventList.Items.Add($script:eventTab[$_].FullFormat)
  152.                 }
  153.             }
  154.             else {
  155.                 $script:eventTab.Keys | %{$EventList.Items.Add($_)}
  156.             }
  157.             $EventList.EndUpdate()
  158.             $EventNumber.Text = "$($EventList.Items.Count)"
  159.         }
  160.     }
  161.  
  162.     $EventClearClicked = {
  163.         $SelectedEventList.BeginUpdate()
  164.         $SelectedEventList.Items.Clear()
  165.         $SelectedEventList.EndUpdate()
  166.         $EventSelectedNumber.Text = ""
  167.     }
  168.  
  169.     $FormInit = {
  170.         $vSphereServer.Items.Clear()
  171.         if($script:vServers){
  172.             $vSphereServer.Items.AddRange($script:vServers)
  173.         }
  174.  
  175.         if($global:DefaultVIServer){
  176.             if($script:vServers -notcontains $global:DefaultVIServer.Name) {
  177.                 $script:vServers += $global:DefaultVIServer.Name
  178.             }
  179.             $vSphereServer.Text = $global:DefaultVIServer.Name
  180.             $script:eventTab = [ordered]@{}
  181.             $vsphereinfo.Text = $global:DefaultVIServer.ExtensionData.Content.About.FullName
  182.             $si = Get-View ServiceInstance -Server $global:DefaultVIServer
  183.             $eventMgr = Get-View $si.Content.EventManager -Server $global:DefaultVIServer
  184.             $eventMgr.Description.EventInfo | %{
  185.                 if('ExtendedEvent','EventEx' -contains $_.Key){
  186.                     $tabKey = $_.FullFormat.Split('|')[0]
  187.                 }
  188.                 else{
  189.                     $tabKey = $_.Key
  190.                 }
  191.                 if(!$tabKey -eq ""){
  192.                     $script:eventTab.Add($tabKey,$_)
  193.                 }
  194.             }
  195.  
  196.             Update-EventList
  197.  
  198.             $EventNumber.Text = "$($EventList.Items.Count)"
  199.         }
  200.         else{
  201.             $vsphereinfo.Text = "<No vSphere Server connected>"
  202.         }
  203.     }
  204.  
  205.     $vSphereServerFocusOn = {
  206.         $EventOMaticForm.AcceptButton = $ConnectButton
  207.     }
  208.  
  209.     $vSphereServerFocusOff = {
  210.         $EventOMaticForm.AcceptButton = $FinishButton
  211.     }
  212.  
  213.     $ConnectClicked = {
  214.         $sessionID = $global:defaultviservers | where {$_.Name -eq $vSphereServer.Text} |
  215.         Select -First 1 -ExpandProperty SessionId
  216.         if($sessionId){
  217.             Connect-VIServer -Server $vSphereServer.Text -Session $sessionId
  218.         }
  219.         else{
  220.             Connect-VIServer -Server $vSphereServer.Text
  221.         }
  222.         $vSphereServer.Text = $global:DefaultVIServer.Name
  223.         $vsphereinfo.text = $global:DefaultVIServer.ExtensionData.Content.About.FullName
  224.         if($script:vServers -notcontains $vSphereServer.Text){
  225.             $script:vServers += $vSphereServer.Text
  226.         }
  227.         & $FormInit
  228.     }
  229.  
  230.     $GenerateCodeClicked = {
  231.         if($SelectedEventList.Items.Count -ne 0){
  232.             $events = $SelectedEventList.Items[0..($SelectedEventList.Items.Count - 1)]
  233.             if($EventPlusRadio.Checked){
  234.                 $code = "Get-VIEventPlus -EventType "
  235.                 $code += ('"' + [string]::Join('","',$events) + '"')
  236.             }
  237.             else{
  238.                 $code = "Get-VIEvent -MaxSamples ([int]::MaxValue) | Where-Object {"
  239.                 $expressions = @()
  240.                 $SelectedEventList.Items[0..($SelectedEventList.Items.Count - 1)] | %{
  241.                     $event =$script:eventTab[$_]
  242.                     if($event.Key -eq "ExtendedEvent"){
  243.                         $expressions += ('($_ -is [VMware.Vim.ExtendedEvent] -and $_.FullFormat -match "^' + $_ + '")')
  244.                     }
  245.                     elseif($event.Key -eq "EventEx"){
  246.                         $expressions += ('($_ -is [VMware.Vim.EventEx] -and $_.FullFormat -match "^' + $_ + '")')
  247.                     }
  248.                     else{
  249.                         $expressions += ('$_ -is [VMware.Vim.' + $_ + ']')
  250.                     }
  251.                 }
  252.                 $code += [string]::Join(' -or ',$expressions)
  253.                 $code += '}'
  254.             }
  255.             [Windows.Forms.Clipboard]::SetText($code)
  256.         }
  257.     }
  258.  
  259.     $OnLoadForm_StateCorrection = {
  260.         #Correct the initial state of the form to prevent the .Net maximized form issue
  261.         $EventOMaticForm.WindowState = $InitialFormWindowState
  262.     }
  263.     #endregion
  264.  
  265.     #region Generated Form Code
  266.     $EventOMaticForm.BackgroundImageLayout = 0
  267.     $EventOMaticForm.CancelButton = $FinishButton
  268.     $System_Drawing_Point = New-Object System.Drawing.Point
  269.     $System_Drawing_Point.X = 18
  270.     $System_Drawing_Point.Y = 0
  271.     $EventOMaticForm.Location = $System_Drawing_Point
  272.     $EventOMaticForm.Text = "Event-O-Matic v$($eventomaticVersion)"
  273.     $EventOMaticForm.Name = "EventOMaticForm"
  274.     $EventOMaticForm.DataBindings.DefaultDataSourceUpdateMode = 0
  275.     $System_Drawing_Size = New-Object System.Drawing.Size
  276.     $System_Drawing_Size.Width = 582
  277.     $System_Drawing_Size.Height = 357
  278.     $EventOMaticForm.ClientSize = $System_Drawing_Size
  279.     $EventOMaticForm.AcceptButton = $FinishButton
  280.     $EventOMaticForm.FormBorderStyle = 3
  281.     $EventOMaticForm.add_Load($FormInit)
  282.  
  283.     $EventDescriptionRadio.TabIndex = 7
  284.     $EventDescriptionRadio.Name = "EventDescriptionRadio"
  285.     $System_Drawing_Size = New-Object System.Drawing.Size
  286.     $System_Drawing_Size.Width = 97
  287.     $System_Drawing_Size.Height = 24
  288.     $EventDescriptionRadio.Size = $System_Drawing_Size
  289.     $EventDescriptionRadio.UseVisualStyleBackColor = $True
  290.  
  291.     $EventDescriptionRadio.Text = "Description"
  292.  
  293.     $System_Drawing_Point = New-Object System.Drawing.Point
  294.     $System_Drawing_Point.X = 110
  295.     $System_Drawing_Point.Y = 279
  296.     $EventDescriptionRadio.Location = $System_Drawing_Point
  297.     $EventDescriptionRadio.DataBindings.DefaultDataSourceUpdateMode = 0
  298.     $EventDescriptionRadio.add_CheckedChanged($EventRadioChanged)
  299.  
  300.     $EventOMaticForm.Controls.Add($EventDescriptionRadio)
  301.  
  302.     $vSphereServer.FormattingEnabled = $True
  303.     $System_Drawing_Size = New-Object System.Drawing.Size
  304.     $System_Drawing_Size.Width = 267
  305.     $System_Drawing_Size.Height = 21
  306.     $vSphereServer.Size = $System_Drawing_Size
  307.     $vSphereServer.DataBindings.DefaultDataSourceUpdateMode = 0
  308.     $vSphereServer.Name = "vSphereServer"
  309.     $System_Drawing_Point = New-Object System.Drawing.Point
  310.     $System_Drawing_Point.X = 110
  311.     $System_Drawing_Point.Y = 25
  312.     $vSphereServer.Location = $System_Drawing_Point
  313.     $vSphereServer.TabIndex = 0
  314.  
  315.     $EventOMaticForm.Controls.Add($vSphereServer)
  316.  
  317.     $EventNameRadio.TabIndex = 6
  318.     $EventNameRadio.Name = "EventNameRadio"
  319.     $System_Drawing_Size = New-Object System.Drawing.Size
  320.     $System_Drawing_Size.Width = 76
  321.     $System_Drawing_Size.Height = 24
  322.     $EventNameRadio.Size = $System_Drawing_Size
  323.     $EventNameRadio.UseVisualStyleBackColor = $True
  324.  
  325.     $EventNameRadio.Text = "Name"
  326.     $EventNameRadio.Checked = $True
  327.  
  328.     $System_Drawing_Point = New-Object System.Drawing.Point
  329.     $System_Drawing_Point.X = 18
  330.     $System_Drawing_Point.Y = 279
  331.     $EventNameRadio.Location = $System_Drawing_Point
  332.     $EventNameRadio.DataBindings.DefaultDataSourceUpdateMode = 0
  333.     $EventNameRadio.TabStop = $True
  334.     $EventNameRadio.add_Click($EventRadioButton)
  335.     $EventNameRadio.add_CheckedChanged($EventRadioChanged)
  336.  
  337.     $EventOMaticForm.Controls.Add($EventNameRadio)
  338.  
  339.     $vsphereinfo.TabIndex = 0
  340.     $System_Drawing_Size = New-Object System.Drawing.Size
  341.     $System_Drawing_Size.Width = 267
  342.     $System_Drawing_Size.Height = 20
  343.     $vsphereinfo.Size = $System_Drawing_Size
  344.     $vsphereinfo.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",7.25,0,3,1)
  345.  
  346.     $System_Drawing_Point = New-Object System.Drawing.Point
  347.     $System_Drawing_Point.X = 110
  348.     $System_Drawing_Point.Y = 48
  349.     $vsphereinfo.Location = $System_Drawing_Point
  350.     $vsphereinfo.DataBindings.DefaultDataSourceUpdateMode = 0
  351.     $vsphereinfo.Name = "vsphereinfo"
  352.  
  353.     $EventOMaticForm.Controls.Add($vsphereinfo)
  354.  
  355.     $EventSelectedNumber.TabIndex = 0
  356.     $System_Drawing_Size = New-Object System.Drawing.Size
  357.     $System_Drawing_Size.Width = 45
  358.     $System_Drawing_Size.Height = 18
  359.     $EventSelectedNumber.Size = $System_Drawing_Size
  360.  
  361.     $System_Drawing_Point = New-Object System.Drawing.Point
  362.     $System_Drawing_Point.X = 341
  363.     $System_Drawing_Point.Y = 114
  364.     $EventSelectedNumber.Location = $System_Drawing_Point
  365.     $EventSelectedNumber.DataBindings.DefaultDataSourceUpdateMode = 0
  366.     $EventSelectedNumber.Name = "EventSelectedNumber"
  367.  
  368.     $EventOMaticForm.Controls.Add($EventSelectedNumber)
  369.  
  370.     $groupBox1.TabIndex = 0
  371.     $System_Drawing_Size = New-Object System.Drawing.Size
  372.     $System_Drawing_Size.Width = 200
  373.     $System_Drawing_Size.Height = 42
  374.     $groupBox1.Size = $System_Drawing_Size
  375.  
  376.     $groupBox1.Text = "Show"
  377.     $System_Drawing_Point = New-Object System.Drawing.Point
  378.     $System_Drawing_Point.X = 18
  379.     $System_Drawing_Point.Y = 262
  380.     $groupBox1.Location = $System_Drawing_Point
  381.     $groupBox1.DataBindings.DefaultDataSourceUpdateMode = 0
  382.     $groupBox1.TabStop = $False
  383.     $groupBox1.Name = "groupBox1"
  384.  
  385.     $EventOMaticForm.Controls.Add($groupBox1)
  386.  
  387.     $EventNumber.TabIndex = 0
  388.     $System_Drawing_Size = New-Object System.Drawing.Size
  389.     $System_Drawing_Size.Width = 40
  390.     $System_Drawing_Size.Height = 18
  391.     $EventNumber.Size = $System_Drawing_Size
  392.  
  393.     $System_Drawing_Point = New-Object System.Drawing.Point
  394.     $System_Drawing_Point.X = 74
  395.     $System_Drawing_Point.Y = 114
  396.     $EventNumber.Location = $System_Drawing_Point
  397.     $EventNumber.DataBindings.DefaultDataSourceUpdateMode = 0
  398.     $EventNumber.Name = "EventNumber"
  399.  
  400.     $EventOMaticForm.Controls.Add($EventNumber)
  401.  
  402.     $Search.TabIndex = 3
  403.     $Search.Name = "Search"
  404.     $System_Drawing_Size = New-Object System.Drawing.Size
  405.     $System_Drawing_Size.Width = 75
  406.     $System_Drawing_Size.Height = 23
  407.     $Search.Size = $System_Drawing_Size
  408.     $Search.UseVisualStyleBackColor = $True
  409.  
  410.     $Search.Text = "Search"
  411.  
  412.     $System_Drawing_Point = New-Object System.Drawing.Point
  413.     $System_Drawing_Point.X = 384
  414.     $System_Drawing_Point.Y = 84
  415.     $Search.Location = $System_Drawing_Point
  416.     $Search.DataBindings.DefaultDataSourceUpdateMode = 0
  417.     $Search.add_Click($SearchClicked)
  418.  
  419.     $EventOMaticForm.Controls.Add($Search)
  420.  
  421.     $System_Drawing_Size = New-Object System.Drawing.Size
  422.     $System_Drawing_Size.Width = 267
  423.     $System_Drawing_Size.Height = 20
  424.     $SearchText.Size = $System_Drawing_Size
  425.     $SearchText.DataBindings.DefaultDataSourceUpdateMode = 0
  426.     $SearchText.Name = "SearchText"
  427.     $System_Drawing_Point = New-Object System.Drawing.Point
  428.     $System_Drawing_Point.X = 110
  429.     $System_Drawing_Point.Y = 85
  430.     $SearchText.Location = $System_Drawing_Point
  431.     $SearchText.TabIndex = 2
  432.     $SearchText.add_Leave($SearchTextFocusOff)
  433.     $SearchText.add_Enter($SearchTextFocusOn)
  434.  
  435.     $EventOMaticForm.Controls.Add($SearchText)
  436.  
  437.     $EventClear.TabIndex = 8
  438.     $EventClear.Name = "EventClear"
  439.     $System_Drawing_Size = New-Object System.Drawing.Size
  440.     $System_Drawing_Size.Width = 51
  441.     $System_Drawing_Size.Height = 22
  442.     $EventClear.Size = $System_Drawing_Size
  443.     $EventClear.UseVisualStyleBackColor = $True
  444.  
  445.     $EventClear.Text = "Clear"
  446.  
  447.     $System_Drawing_Point = New-Object System.Drawing.Point
  448.     $System_Drawing_Point.X = 407
  449.     $System_Drawing_Point.Y = 262
  450.     $EventClear.Location = $System_Drawing_Point
  451.     $EventClear.DataBindings.DefaultDataSourceUpdateMode = 0
  452.     $EventClear.add_Click($EventClearClicked)
  453.  
  454.     $EventOMaticForm.Controls.Add($EventClear)
  455.  
  456.     $FinishButton.TabIndex = 11
  457.     $FinishButton.Name = "FinishButton"
  458.     $System_Drawing_Size = New-Object System.Drawing.Size
  459.     $System_Drawing_Size.Width = 91
  460.     $System_Drawing_Size.Height = 23
  461.     $FinishButton.Size = $System_Drawing_Size
  462.     $FinishButton.UseVisualStyleBackColor = $True
  463.  
  464.     $FinishButton.Text = "Finish"
  465.  
  466.     $System_Drawing_Point = New-Object System.Drawing.Point
  467.     $System_Drawing_Point.X = 460
  468.     $System_Drawing_Point.Y = 321
  469.     $FinishButton.Location = $System_Drawing_Point
  470.     $FinishButton.DataBindings.DefaultDataSourceUpdateMode = 0
  471.     $FinishButton.DialogResult = 1
  472.     $FinishButton.add_Click($FinishClicked)
  473.  
  474.     $EventOMaticForm.Controls.Add($FinishButton)
  475.  
  476.     $System_Drawing_Size = New-Object System.Drawing.Size
  477.     $System_Drawing_Size.Width = 138
  478.     $System_Drawing_Size.Height = 24
  479.     $EventPlusRadio.Size = $System_Drawing_Size
  480.  
  481.     $EventPlusRadio.Text = "Use Get-VIEventPlus"
  482.     $EventPlusRadio.Name = "EventPlusRadio"
  483.     $EventPlusRadio.UseVisualStyleBackColor = $True
  484.     $System_Drawing_Point = New-Object System.Drawing.Point
  485.     $System_Drawing_Point.X = 18
  486.     $System_Drawing_Point.Y = 320
  487.     $EventPlusRadio.Location = $System_Drawing_Point
  488.     $EventPlusRadio.DataBindings.DefaultDataSourceUpdateMode = 0
  489.  
  490.     $EventPlusRadio.TabIndex = 9
  491.  
  492.     $EventOMaticForm.Controls.Add($EventPlusRadio)
  493.  
  494.     $GenerateCodeButton.TabIndex = 10
  495.     $GenerateCodeButton.Name = "GenerateCodeButton"
  496.     $System_Drawing_Size = New-Object System.Drawing.Size
  497.     $System_Drawing_Size.Width = 113
  498.     $System_Drawing_Size.Height = 23
  499.     $GenerateCodeButton.Size = $System_Drawing_Size
  500.     $GenerateCodeButton.UseVisualStyleBackColor = $True
  501.  
  502.     $GenerateCodeButton.Text = "Generate Code"
  503.  
  504.     $System_Drawing_Point = New-Object System.Drawing.Point
  505.     $System_Drawing_Point.X = 162
  506.     $System_Drawing_Point.Y = 321
  507.     $GenerateCodeButton.Location = $System_Drawing_Point
  508.     $GenerateCodeButton.DataBindings.DefaultDataSourceUpdateMode = 0
  509.     $GenerateCodeButton.add_Click($GenerateCodeClicked)
  510.  
  511.     $EventOMaticForm.Controls.Add($GenerateCodeButton)
  512.  
  513.     $SelectedEventList.FormattingEnabled = $True
  514.     $System_Drawing_Size = New-Object System.Drawing.Size
  515.     $System_Drawing_Size.Width = 270
  516.     $System_Drawing_Size.Height = 121
  517.     $SelectedEventList.Size = $System_Drawing_Size
  518.     $SelectedEventList.DataBindings.DefaultDataSourceUpdateMode = 0
  519.     $SelectedEventList.Name = "SelectedEventList"
  520.     $System_Drawing_Point = New-Object System.Drawing.Point
  521.     $System_Drawing_Point.X = 281
  522.     $System_Drawing_Point.Y = 135
  523.     $SelectedEventList.Location = $System_Drawing_Point
  524.     $SelectedEventList.TabIndex = 5
  525.     $SelectedEventList.add_Click($EventClicked)
  526.  
  527.     $EventOMaticForm.Controls.Add($SelectedEventList)
  528.  
  529.     $label4.TabIndex = 0
  530.     $System_Drawing_Size = New-Object System.Drawing.Size
  531.     $System_Drawing_Size.Width = 54
  532.     $System_Drawing_Size.Height = 16
  533.     $label4.Size = $System_Drawing_Size
  534.     $label4.Text = "Selected"
  535.  
  536.     $System_Drawing_Point = New-Object System.Drawing.Point
  537.     $System_Drawing_Point.X = 281
  538.     $System_Drawing_Point.Y = 115
  539.     $label4.Location = $System_Drawing_Point
  540.     $label4.DataBindings.DefaultDataSourceUpdateMode = 0
  541.     $label4.Name = "label4"
  542.  
  543.     $EventOMaticForm.Controls.Add($label4)
  544.  
  545.     $EventList.FormattingEnabled = $True
  546.     $System_Drawing_Size = New-Object System.Drawing.Size
  547.     $System_Drawing_Size.Width = 256
  548.     $System_Drawing_Size.Height = 121
  549.     $EventList.Size = $System_Drawing_Size
  550.     $EventList.DataBindings.DefaultDataSourceUpdateMode = 0
  551.     $EventList.Name = "EventList"
  552.     $System_Drawing_Point = New-Object System.Drawing.Point
  553.     $System_Drawing_Point.X = 18
  554.     $System_Drawing_Point.Y = 135
  555.     $EventList.Location = $System_Drawing_Point
  556.     #   $EventList.Sorted = $True
  557.     $EventList.TabIndex = 4
  558.     $EventList.add_MouseMove($EventMouseMove)
  559.     $EventList.add_Click($EventClicked)
  560.  
  561.     $EventOMaticForm.Controls.Add($EventList)
  562.  
  563.     $label2.TabIndex = 0
  564.     $System_Drawing_Size = New-Object System.Drawing.Size
  565.     $System_Drawing_Size.Width = 49
  566.     $System_Drawing_Size.Height = 18
  567.     $label2.Size = $System_Drawing_Size
  568.     $label2.Text = "Events"
  569.  
  570.     $System_Drawing_Point = New-Object System.Drawing.Point
  571.     $System_Drawing_Point.X = 18
  572.     $System_Drawing_Point.Y = 114
  573.     $label2.Location = $System_Drawing_Point
  574.     $label2.DataBindings.DefaultDataSourceUpdateMode = 0
  575.     $label2.Name = "label2"
  576.  
  577.     $EventOMaticForm.Controls.Add($label2)
  578.  
  579.     $ConnectButton.TabIndex = 1
  580.     $ConnectButton.Name = "ConnectButton"
  581.     $System_Drawing_Size = New-Object System.Drawing.Size
  582.     $System_Drawing_Size.Width = 75
  583.     $System_Drawing_Size.Height = 23
  584.     $ConnectButton.Size = $System_Drawing_Size
  585.     $ConnectButton.UseVisualStyleBackColor = $True
  586.  
  587.     $ConnectButton.Text = "Connect"
  588.  
  589.     $System_Drawing_Point = New-Object System.Drawing.Point
  590.     $System_Drawing_Point.X = 383
  591.     $System_Drawing_Point.Y = 22
  592.     $ConnectButton.Location = $System_Drawing_Point
  593.     $ConnectButton.DataBindings.DefaultDataSourceUpdateMode = 0
  594.     $ConnectButton.add_Click($ConnectClicked)
  595.  
  596.     $EventOMaticForm.Controls.Add($ConnectButton)
  597.  
  598.     $label1.TabIndex = 0
  599.     $System_Drawing_Size = New-Object System.Drawing.Size
  600.     $System_Drawing_Size.Width = 85
  601.     $System_Drawing_Size.Height = 17
  602.     $label1.Size = $System_Drawing_Size
  603.     $label1.Text = "vSphere Server"
  604.  
  605.     $System_Drawing_Point = New-Object System.Drawing.Point
  606.     $System_Drawing_Point.X = 18
  607.     $System_Drawing_Point.Y = 27
  608.     $label1.Location = $System_Drawing_Point
  609.     $label1.DataBindings.DefaultDataSourceUpdateMode = 0
  610.     $label1.Name = "label1"
  611.  
  612.     $EventOMaticForm.Controls.Add($label1)
  613.  
  614.     $EventTooltip.ToolTipTitle = "Description"
  615.  
  616.     #endregion
  617.  
  618.     #region RunForm Diakog
  619.     #Save the initial state of the form
  620.     $InitialFormWindowState = $EventOMaticForm.WindowState
  621.     #Init the OnLoad event to correct the initial state of the form
  622.     $EventOMaticForm.add_Load($OnLoadForm_StateCorrection)
  623.     #Show the Form
  624.     $EventOMaticForm.ShowDialog()| Out-Null
  625.     #endregion
  626.  
  627. }
  628.  
  629. #region Main
  630. if(!$PSVersionTable -or $PSVersionTable.PSVersion.Major -lt 3){
  631.     Write-Error "The script requires at least PowerShell v3."
  632.     return
  633. }
  634. Try {
  635.     Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction Stop
  636. }
  637. Catch {
  638.     Write-Error "The script requires that the PowerCLI pssnapin is loaded."
  639.     return
  640. }
  641.  
  642. $eventomaticVersion = "3.2"
  643. $eventomaticIni = ".\Event-O-Matic.ini"
  644.  
  645. if(Test-Path -Path $eventomaticIni){
  646.     $script:vServers = @(Get-Content -Path $eventomaticIni)
  647. }
  648.  
  649. # Show form
  650.  
  651. GenerateForm
  652.  
  653. $script:vServers | Set-Content -Path $eventomaticIni -Force -Confirm:$false
  654.  
  655. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement