#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0 # Generated On: 7/1/2009 10:37 AM # Generated By: cody.bunch ######################################################################## #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 $findSnaps = New-Object System.Windows.Forms.Button $richTextBox1 = New-Object System.Windows.Forms.RichTextBox $daysOld = New-Object System.Windows.Forms.NumericUpDown $label2 = New-Object System.Windows.Forms.Label $vCenterHost = New-Object System.Windows.Forms.TextBox $label1 = New-Object System.Windows.Forms.Label $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $findSnaps_OnClick= { $days_Old = $daysOld.Value $richTextBox1.Text = "Connecting to VI Server...`n" Get-Credential | Connect-VIServer -Server $vCenterHost.Text $richTextBox1.Text += "Looking for snapshots older than $days_Old days old...`n" $snapshots = Get-VM | Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-$days_Old) } if ($snapshots){ $snapshots | %{ $VM = $_.VM.Name $snapshot = $_.Name $created = $_.Created $richTextBox1.Text += "`nVM: $VM`nSnapshot: $snapshot`nCreated: $created" } } else { $richTextBox1.Text += "No snapshots found." } } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $form1.Text = 'Snapshot Finder' $form1.Name = 'form1' $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 238 $System_Drawing_Size.Height = 209 $form1.ClientSize = $System_Drawing_Size $findSnaps.TabIndex = 5 $findSnaps.Name = 'findSnaps' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $findSnaps.Size = $System_Drawing_Size $findSnaps.UseVisualStyleBackColor = $True $findSnaps.Text = 'Find' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 82 $System_Drawing_Point.Y = 170 $findSnaps.Location = $System_Drawing_Point $findSnaps.DataBindings.DefaultDataSourceUpdateMode = 0 $findSnaps.add_Click($findSnaps_OnClick) $form1.Controls.Add($findSnaps) $richTextBox1.Name = 'richTextBox1' $richTextBox1.Text = '' $richTextBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 16 $System_Drawing_Point.Y = 67 $richTextBox1.Location = $System_Drawing_Point $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 207 $System_Drawing_Size.Height = 96 $richTextBox1.Size = $System_Drawing_Size $richTextBox1.TabIndex = 4 $form1.Controls.Add($richTextBox1) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 20 $daysOld.Size = $System_Drawing_Size $daysOld.DataBindings.DefaultDataSourceUpdateMode = 0 $daysOld.Name = 'daysOld' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 123 $System_Drawing_Point.Y = 40 $daysOld.Location = $System_Drawing_Point $daysOld.TabIndex = 3 $form1.Controls.Add($daysOld) $label2.TabIndex = 2 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 23 $label2.Size = $System_Drawing_Size $label2.Text = 'Days Old' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 123 $System_Drawing_Point.Y = 13 $label2.Location = $System_Drawing_Point $label2.DataBindings.DefaultDataSourceUpdateMode = 0 $label2.Name = 'label2' $form1.Controls.Add($label2) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 20 $vCenterHost.Size = $System_Drawing_Size $vCenterHost.DataBindings.DefaultDataSourceUpdateMode = 0 $vCenterHost.Text = 'esx.domain.local' $vCenterHost.Name = 'vCenterHost' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 16 $System_Drawing_Point.Y = 40 $vCenterHost.Location = $System_Drawing_Point $vCenterHost.TabIndex = 1 $form1.Controls.Add($vCenterHost) $label1.TabIndex = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 100 $System_Drawing_Size.Height = 23 $label1.Size = $System_Drawing_Size $label1.Text = 'ESX Host' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 16 $System_Drawing_Point.Y = 13 $label1.Location = $System_Drawing_Point $label1.DataBindings.DefaultDataSourceUpdateMode = 0 $label1.Name = 'label1' $form1.Controls.Add($label1) #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