Get-PSSnapin -registered | Add-PSSnapin -passthru -ErrorAction SilentlyContinue Import-Module "C:\Users\Eric Sloof\Downloads\PowerShell\vitoolkitextensions-47867\coreModule\viToolkitExtensions.psm1" #[Reflection.Assembly]::LoadWithPartialType("System.Drawing") $Server = Connect-VIServer -Server 192.168.178.250 -User Administrator -Password vmware #Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0 # Generated On: 5-5-2009 13:53 # Generated By: Eric Sloof ######################################################################## #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 $button2 = New-Object System.Windows.Forms.Button $textBox1 = New-Object System.Windows.Forms.TextBox $button1 = New-Object System.Windows.Forms.Button $pictureBox1 = New-Object System.Windows.Forms.PictureBox $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $button1_OnClick= { #TODO: Place custom script here $vm = Get-VM -Name "Connection" $vmView = $vm | Get-View $vmView.CreateScreenshot_Task() $vmxPath = $vmView.Config.Files.VmPathName $pngPath = $vmxPath.Replace(".vmx", "-screenshot-0.png") Copy-TkeDatastoreFile -source $pngPath -sourceServer $Server -sourceDatacenter (get-datacenter -server $server) -destination "C:\Users\Eric Sloof\Documents\vm.png" ($pictureBox1).ImageLocation = "C:\Users\Eric Sloof\Documents\vm.png" } $button2_OnClick= { #TODO: Place custom script here # Convert the PNG to TIFF. $image = [System.Drawing.Image]::FromFile("C:\Users\Eric Sloof\Documents\vm.png") $image.Save("C:\Users\Eric Sloof\Documents\vm.tif", [System.Drawing.Imaging.ImageFormat]::TIFF) # OCR it! (Requires Microsoft Office Document Imaging) $modi = new-object -com MODI.Document $modi.Create("C:\Users\Eric Sloof\Documents\vm.tif") $modi.OCR() $OCRText = ($modi.Images | select -expand Layout).Text $textBox1.text = $OCRText } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $form1.BackColor = [System.Drawing.Color]::FromArgb(255,191,205,219) $form1.Text = 'NTPRO.NL Blue Screen Detector' $form1.Name = 'form1' $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 493 $System_Drawing_Size.Height = 277 $form1.ClientSize = $System_Drawing_Size $form1.FormBorderStyle = 3 $button2.TabIndex = 3 $button2.Name = 'button2' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 237 $System_Drawing_Size.Height = 23 $button2.Size = $System_Drawing_Size $button2.UseVisualStyleBackColor = $True $button2.Text = 'Run OCR' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 247 $System_Drawing_Point.Y = 246 $button2.Location = $System_Drawing_Point $button2.DataBindings.DefaultDataSourceUpdateMode = 0 $button2.add_Click($button2_OnClick) $form1.Controls.Add($button2) $textBox1.Multiline = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 238 $System_Drawing_Size.Height = 228 $textBox1.Size = $System_Drawing_Size $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $textBox1.Name = 'textBox1' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 247 $System_Drawing_Point.Y = 10 $textBox1.Location = $System_Drawing_Point $textBox1.TabIndex = 2 $form1.Controls.Add($textBox1) $button1.TabIndex = 1 $button1.Name = 'button1' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 227 $System_Drawing_Size.Height = 25 $button1.Size = $System_Drawing_Size $button1.UseVisualStyleBackColor = $True $button1.Text = 'Get Screen Shot' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 245 $button1.Location = $System_Drawing_Point $button1.DataBindings.DefaultDataSourceUpdateMode = 0 $button1.add_Click($button1_OnClick) $form1.Controls.Add($button1) $pictureBox1.TabIndex = 0 $pictureBox1.SizeMode = 1 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 228 $System_Drawing_Size.Height = 228 $pictureBox1.Size = $System_Drawing_Size $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 11 $pictureBox1.Location = $System_Drawing_Point $pictureBox1.TabStop = $False $pictureBox1.Name = 'pictureBox1' $pictureBox1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Controls.Add($pictureBox1) #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