GUI tool to change boot delay, iops, pvscsi and disk to eager-zeroed thick

Version 1

    i did it myself

     

     

    #Generated Form Function

    function GenerateForm {

    ########################################################################

    # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0

    # Generated On: 6/20/2013 10:16 AM

    # Generated By: ts-harshavardh.gupta

    ########################################################################

     

     

    #region Import the Assemblies

    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null

    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null

    #endregion

     

     

    #region Generated Form Objects

    $form1 = New-Object System.Windows.Forms.Form

    $label3 = New-Object System.Windows.Forms.Label

    $tgt_datastore = New-Object System.Windows.Forms.TextBox

    $disconnect_btn = New-Object System.Windows.Forms.Button

    $eagerzero_btn = New-Object System.Windows.Forms.Button

    $pvscsi_btn = New-Object System.Windows.Forms.Button

    $bootdelay_btn = New-Object System.Windows.Forms.Button

    $IOPS_btn = New-Object System.Windows.Forms.Button

    $label2 = New-Object System.Windows.Forms.Label

    $tgt_vm = New-Object System.Windows.Forms.TextBox

    $Login_btn = New-Object System.Windows.Forms.Button

    $vCenter_txt = 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.

    $disconnect_btn_OnClick=

    {

    #TODO: Place custom script here

    #Disconnect from vCenter server

      Disconnect-VIServer -Confirm:$false

     

      #Close Form

      $form1.close()

    }

     

     

    $IOPS_btn_OnClick=

    {

    #TODO: Place custom script here NOW WORKING

    $DiskLimitIOPerSecond = 500

    # $DiskLimitIOPerSecond = -1 # Unlimited

     

     

    $vm = Get-VM -Name $tgt_vm.text

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $vm.ExtensionData.Config.Hardware.Device |

    where {$_ -is [VMware.Vim.VirtualDisk]} | %{

      $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

      $dev.Operation = "edit"

      $dev.Device = $_

      $dev.Device.StorageIOAllocation.Limit = $DiskLimitIOPerSecond

      $spec.DeviceChange += $dev

    }

    $vm.ExtensionData.ReconfigVM_Task($spec)

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [System.Windows.Forms.MessageBox]::Show("Task Done")

    }

     

     

    $Login_btn_OnClick=

    {

    #TODO: Place custom script here NOW WORKING

    if ((Get-PSSnapin "VMware.VimAutomation.Core" -ErrorAction SilentlyContinue) -eq $null) {

    Add-PSSnapin "VMware.VimAutomation.Core"

    }

     

     

    #Connect to vCenter

    Connect-VIServer $vCenter_txt.Text

    $form1.text=$vCenter_txt.text

    }

     

     

    $handler_label1_Click=

    {

    #TODO: Place custom script here

     

     

    }

     

     

    $eagerzero_btn_OnClick=

    {

    #TODO: Place custom script here

    $vm = Get-VM -Name $tgt_vm.text

    $TargetDatastore=Get-Datastore -Name $tgt_datastore.text

    if($TargetDatastore -eq $null){

      [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

      [System.Windows.Forms.MessageBox]::Show("Input Target Datastore First")

    }

    else

    {

    Get-VM $vm | Move-VM -Datastore $TargetDatastore -DiskStorageFormat EagerZeroedThick

       write-host $vm $TargetDatastore

       Start-Sleep -s 30

    }

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [System.Windows.Forms.MessageBox]::Show("Task Done")

    }

     

     

    $bootdelay_btn_OnClick=

    {

    #TODO: Place custom script here NOW WORKING

    $vm = Get-VM -Name $tgt_vm.text

    $BootDelay = 10000

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec

    $spec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions

    $spec.BootOptions.BootDelay = $BootDelay

    $vm.Extensiondata.ReconfigVM_Task($spec)

     

     

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [System.Windows.Forms.MessageBox]::Show("Task Done")

    }

     

     

    $pvscsi_btn_OnClick=

    {

    #TODO: Place custom script here

    #Change scsi to paravirtualized NOW WORKING

    $vm = Get-VM -Name $tgt_vm.text

    $scsiController = Get-HardDisk -VM $vm | Select -First 1 | Get-ScsiController

    Set-ScsiController -ScsiController $scsiController -Type ParaVirtual

     

     

    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [System.Windows.Forms.MessageBox]::Show("Task Done")

    }

     

     

    $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 = 204

    $System_Drawing_Size.Width = 529

    $form1.ClientSize = $System_Drawing_Size

    $form1.DataBindings.DefaultDataSourceUpdateMode = 0

    $form1.Name = "form1"

    $form1.Text = "Basic Tasks"

     

     

    $label3.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 26

    $System_Drawing_Point.Y = 173

    $label3.Location = $System_Drawing_Point

    $label3.Name = "label3"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 88

    $label3.Size = $System_Drawing_Size

    $label3.TabIndex = 11

    $label3.Text = "Datastore Name"

     

     

    $form1.Controls.Add($label3)

     

     

    $tgt_datastore.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 114

    $System_Drawing_Point.Y = 174

    $tgt_datastore.Location = $System_Drawing_Point

    $tgt_datastore.Name = "tgt_datastore"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 153

    $tgt_datastore.Size = $System_Drawing_Size

    $tgt_datastore.TabIndex = 10

     

     

    $form1.Controls.Add($tgt_datastore)

     

     

     

     

    $disconnect_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 405

    $System_Drawing_Point.Y = 12

    $disconnect_btn.Location = $System_Drawing_Point

    $disconnect_btn.Name = "disconnect_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 21

    $System_Drawing_Size.Width = 118

    $disconnect_btn.Size = $System_Drawing_Size

    $disconnect_btn.TabIndex = 9

    $disconnect_btn.Text = "Disconnect"

    $disconnect_btn.UseVisualStyleBackColor = $True

    $disconnect_btn.add_Click($disconnect_btn_OnClick)

     

     

    $form1.Controls.Add($disconnect_btn)

     

     

     

     

    $eagerzero_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 289

    $System_Drawing_Point.Y = 171

    $eagerzero_btn.Location = $System_Drawing_Point

    $eagerzero_btn.Name = "eagerzero_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 25

    $System_Drawing_Size.Width = 83

    $eagerzero_btn.Size = $System_Drawing_Size

    $eagerzero_btn.TabIndex = 8

    $eagerzero_btn.Text = "Eager Zeroed"

    $eagerzero_btn.UseVisualStyleBackColor = $True

    $eagerzero_btn.add_Click($eagerzero_btn_OnClick)

     

     

    $form1.Controls.Add($eagerzero_btn)

     

     

     

     

    $pvscsi_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 285

    $System_Drawing_Point.Y = 131

    $pvscsi_btn.Location = $System_Drawing_Point

    $pvscsi_btn.Name = "pvscsi_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 27

    $System_Drawing_Size.Width = 88

    $pvscsi_btn.Size = $System_Drawing_Size

    $pvscsi_btn.TabIndex = 7

    $pvscsi_btn.Text = "PV SCSI"

    $pvscsi_btn.UseVisualStyleBackColor = $True

    $pvscsi_btn.add_Click($pvscsi_btn_OnClick)

     

     

    $form1.Controls.Add($pvscsi_btn)

     

     

     

     

    $bootdelay_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 285

    $System_Drawing_Point.Y = 93

    $bootdelay_btn.Location = $System_Drawing_Point

    $bootdelay_btn.Name = "bootdelay_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 23

    $System_Drawing_Size.Width = 88

    $bootdelay_btn.Size = $System_Drawing_Size

    $bootdelay_btn.TabIndex = 6

    $bootdelay_btn.Text = "Boot Delay"

    $bootdelay_btn.UseVisualStyleBackColor = $True

    $bootdelay_btn.add_Click($bootdelay_btn_OnClick)

     

     

    $form1.Controls.Add($bootdelay_btn)

     

     

     

     

    $IOPS_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 285

    $System_Drawing_Point.Y = 56

    $IOPS_btn.Location = $System_Drawing_Point

    $IOPS_btn.Name = "IOPS_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 88

    $IOPS_btn.Size = $System_Drawing_Size

    $IOPS_btn.TabIndex = 5

    $IOPS_btn.Text = "Limit IOPS"

    $IOPS_btn.UseVisualStyleBackColor = $True

    $IOPS_btn.add_Click($IOPS_btn_OnClick)

     

     

    $form1.Controls.Add($IOPS_btn)

     

     

    $label2.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 25

    $System_Drawing_Point.Y = 56

    $label2.Location = $System_Drawing_Point

    $label2.Name = "label2"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 81

    $label2.Size = $System_Drawing_Size

    $label2.TabIndex = 4

    $label2.Text = "VM Name"

     

     

    $form1.Controls.Add($label2)

     

     

    $tgt_vm.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 106

    $System_Drawing_Point.Y = 56

    $tgt_vm.Location = $System_Drawing_Point

    $tgt_vm.Name = "tgt_vm"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 159

    $tgt_vm.Size = $System_Drawing_Size

    $tgt_vm.TabIndex = 3

     

     

    $form1.Controls.Add($tgt_vm)

     

     

     

     

    $Login_btn.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 285

    $System_Drawing_Point.Y = 13

    $Login_btn.Location = $System_Drawing_Point

    $Login_btn.Name = "Login_btn"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 89

    $Login_btn.Size = $System_Drawing_Size

    $Login_btn.TabIndex = 2

    $Login_btn.Text = "Login"

    $Login_btn.UseVisualStyleBackColor = $True

    $Login_btn.add_Click($Login_btn_OnClick)

     

     

    $form1.Controls.Add($Login_btn)

     

     

    $vCenter_txt.DataBindings.DefaultDataSourceUpdateMode = 0

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 106

    $System_Drawing_Point.Y = 14

    $vCenter_txt.Location = $System_Drawing_Point

    $vCenter_txt.Name = "vCenter_txt"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 20

    $System_Drawing_Size.Width = 162

    $vCenter_txt.Size = $System_Drawing_Size

    $vCenter_txt.TabIndex = 1

     

     

    $form1.Controls.Add($vCenter_txt)

     

     

    $label1.DataBindings.DefaultDataSourceUpdateMode = 0

     

     

    $System_Drawing_Point = New-Object System.Drawing.Point

    $System_Drawing_Point.X = 26

    $System_Drawing_Point.Y = 18

    $label1.Location = $System_Drawing_Point

    $label1.Name = "label1"

    $System_Drawing_Size = New-Object System.Drawing.Size

    $System_Drawing_Size.Height = 16

    $System_Drawing_Size.Width = 88

    $label1.Size = $System_Drawing_Size

    $label1.TabIndex = 0

    $label1.Text = "vCenter Server"

    $label1.add_Click($handler_label1_Click)

     

     

    $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