Advertisement
Guest User

Powershell

a guest
Dec 10th, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #loads module
  2. Get-Module -ListAvailable VMware* | Import-Module | Out-Null
  3. #Name of cluster
  4. $Cluster= ""
  5. #IP or name of VCenter
  6. $vCenterName = ""
  7. $vCenterUser = ""
  8. $vCenterPass = ""
  9. Connect-VIServer -Server $vCenterName -User $vCenterUser -Password $vCenterPass -WarningAction SilentlyContinue | out-null
  10.  
  11.  
  12. #Function that gets VM folders, filters all static folders away thats not needed.
  13. Function Get-VMFolder() {
  14.     $VMListe = (Get-Folder).name | Where-Object {$_ -notlike "Datacenters" -and $_ -notlike "vm" -and $_ -notlike "host" -and $_ -notlike "datastore" -and $_ -notlike "Discovered virtual machine" -and $_ -notlike "network"}
  15.     return $VMListe
  16. }
  17.  
  18. #Function that gets VM information, gets VM name, and guest OS ip address, aswell as option to give other filename in if statement.
  19. function Get-VMStats(){
  20.     $Folder= $VMInfoList.Text
  21.     $VMName =(get-folder -name $Folder| Get-VM).Guest.VM.Name
  22.     $VMIP = (get-folder -name $Folder| Get-VM).Guest.IPAddress | Select-String -Pattern "10.108*"
  23.    
  24.     $i=0
  25.     if ($FilNavnRadioButton.Checked -eq $true) {
  26.         New-item -ItemType File -Path ("~/Desktop/"+$VMInfoTextBox+".txt") -Force
  27.         ForEach ($Monkey in $VMName) {
  28.        
  29.         $i++
  30.         }
  31.     }
  32.     if ($DefaultRadioButton.Checked -eq $true){
  33.         New-item -ItemType File -Path ("~/Desktop/"+$Folder+".txt") -Force
  34.         ForEach ($Monkey in $VMName) {
  35.        
  36.             $VMName[$i] + "  "+ $VMIP[$i]+" Brugernavn: root Password: P@ssW0rd" | out-file ("~/Desktop/"+$Folder+".txt") -append
  37.             $i++
  38.         }
  39.     }
  40. }
  41. #Starts VMs, by getting VM Folder -> VMs -> Foreach that starts VMs async.
  42. Function Start-VMs() {
  43.     $Folder= $VMManListe.Text
  44.     Get-Folder -Name $Folder | Get-VM | ForEach-Object{Start-VM -vm $_ -RunAsync -Confirm:$false}
  45. }
  46. #Stops VMs, by getting VM Folder -> VMs -> Foreach that starts VMs async.
  47. Function Stop-VMs(){
  48.     $Folder= $VMManListe.Text
  49.     Get-Folder -Name $Folder | Get-VM | ForEach-Object{Stop-VM -vm $_ -RunAsync -Confirm:$false}
  50. }
  51. #Removes VMs, removes the entire folder, deletepermanently parameter makes sure all data is removed from SAN.
  52. Function Remove-VMFolder() {
  53.     $Folder= $VMManListe.Text
  54.     Remove-Folder -Folder $Folder -DeletePermanently
  55. }
  56. #Gets all VM Templates in Datacenter.
  57. Function Get-VMTemplates () {
  58.     $TListe = Get-Template
  59.     return $TListe
  60. }
  61. <#
  62. HovedFunktion der deployer VMs, laver en folder, navngivning er via Text input box i GUI + Grp og nummer for VM. Deployer til Freenas$i hvor I er et nr. mellem 1-7
  63. Eksisterende hold henter jeg antallet af VM i folders som int, og bruger den til navngivning af nye VMs.
  64. #>
  65. <#
  66. Main function that deploys VMs,  Makes a folder, naming is done via text input box in GUI, + Grp and number for VM. Deploys to Freenas$i where i is a number between 1-7.
  67. Eksisterende Hold gets number of VMs in folder as a int, and uses that for naming new vms.
  68. #>
  69. Function DeployVM ($mForm)
  70. {
  71.     if ($NyVMRadButton.Checked -eq $true){
  72.         $Hold = $TeamTextBox.Text
  73.         $Antal = $AntalTextBox.Text
  74.         $VMtemplate = $TemplateListe.Text
  75.         Write-Host "Hovedprocessen startes."
  76.         Write-Host "Template -> $VMtemplate"
  77.         Write-Host "Antal -> $Antal  -  " $Antal.GetType()
  78.         Write-Host "Hold -> $Hold"
  79.  
  80.         $i=1
  81.         new-folder -Name $Hold -Location (Get-folder vm)
  82.  
  83.         1..$Antal | foreach {
  84.             if ($i -ge 8){
  85.                 $i=1
  86.             }
  87.             $y="{0:D1}" -f $_
  88.             $VM_name= $Hold+'-Grp'+$y
  89.             $ESXi=Get-Cluster | Get-VMHost -state connected | Get-Random
  90.             write-host "Creation of VM $VM_name initiated" -foreground green
  91.             New-VM -Name $VM_Name -template $VMtemplate -VMHost $ESXi -Datastore "FreeNas$i" -Location $Hold -RunAsync
  92.             $i++
  93.         }
  94.     }
  95.     if ($ExistingVMRadButton.Checked -eq $true){
  96.         $Folder= $ExistingTeamList.Text
  97.         $VMCount =((get-folder -name $Folder| Get-VM).Guest.VM.Name).count +1
  98.  
  99.         $Hold = $Folder
  100.         [int]$IntVMCount= $VMCount
  101.         [int]$IntAntalTextBox= $AntalTextBox.Text
  102.         $Antal = $IntVMCount+ $IntAntalTextBox -1
  103.         $VMtemplate = $TemplateListe.Text
  104.         Write-Host "Hovedprocessen startes."
  105.         Write-Host "Template -> $VMtemplate"
  106.         Write-Host "Antal -> $IntAntalTextBox"
  107.         Write-Host "Hold -> $Hold"
  108.         $i=1
  109.         $VMcount..$Antal | foreach {
  110.             if ($i -ge 8){
  111.                 $i=1
  112.             }
  113.             $y="{0:D1}" -f $_
  114.             $VM_name= $Hold+'-Grp'+$y
  115.             $ESXi=Get-Cluster | Get-VMHost -state connected | Get-Random
  116.             $RDataStore= Get-DatastoreCluster | Get-Datastore | Get-Random
  117.             write-host "Creation of VM $VM_name initiated" -foreground green
  118.             New-VM -Name $VM_Name -template $VMtemplate -VMHost $ESXi -Datastore "FreeNas$i" -Location $Hold -RunAsync
  119.             $i++
  120.     }
  121.     }
  122.  
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. function CreateForm {
  131.  
  132.  
  133. Add-Type -AssemblyName System.Windows.Forms
  134. Add-Type -AssemblyName System.drawing
  135.  
  136. #Form Setup
  137. $form1 = New-Object System.Windows.Forms.Form
  138.  
  139. $TabControl = New-object System.Windows.Forms.TabControl
  140. $DeployVMPage = New-Object System.Windows.Forms.TabPage
  141. $VMManagementPage = New-Object System.Windows.Forms.TabPage
  142. $VMINfoPage = New-Object System.Windows.Forms.TabPage
  143.  
  144.  
  145. $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  146.  
  147. #Form Parameter
  148. $form1.Text = "ESXI VCenter VM Management"
  149. $form1.Name = "form1"
  150. $form1.DataBindings.DefaultDataSourceUpdateMode = 0
  151. $System_Drawing_Size = New-Object System.Drawing.Size
  152. $System_Drawing_Size.Width = 350
  153. $System_Drawing_Size.Height = 350
  154. $form1.ClientSize = $System_Drawing_Size
  155.  
  156.  
  157. #Tab Control
  158. $tabControl.DataBindings.DefaultDataSourceUpdateMode = 0
  159. $System_Drawing_Point = New-Object System.Drawing.Point
  160. $System_Drawing_Point.X = 5
  161. $System_Drawing_Point.Y = 5
  162. $tabControl.Location = $System_Drawing_Point
  163. $tabControl.Name = "tabControl"
  164. $System_Drawing_Size = New-Object System.Drawing.Size
  165. $System_Drawing_Size.Height = 340
  166. $System_Drawing_Size.Width = 340
  167. $tabControl.Size = $System_Drawing_Size
  168. $form1.Controls.Add($tabControl)
  169.  
  170. $DeployVMPage.DataBindings.DefaultDataSourceUpdateMode = 0
  171. $DeployVMPage.UseVisualStyleBackColor = $True
  172. $DeployVMPage.Name = "Deploy VM"
  173. $DeployVMPage.Text = "Deploy VM”
  174. $tabControl.Controls.Add($DeployVMPage)
  175.  
  176. $VMManagementPage.DataBindings.DefaultDataSourceUpdateMode = 0
  177. $VMManagementPage.UseVisualStyleBackColor = $True
  178. $VMManagementPage.Name = "VM Management"
  179. $VMManagementPage.Text = "VM Management”
  180. $tabControl.Controls.Add($VMManagementPage)
  181.  
  182. $VMInfoPage.DataBindings.DefaultDataSourceUpdateMode = 0
  183. $VMInfoPage.UseVisualStyleBackColor = $True
  184. $VMInfoPage.Name = "VM Info"
  185. $VMInfoPage.Text = "VM Info”
  186. $tabControl.Controls.Add($VMInfoPage)
  187.  
  188.  
  189. #DeployVMPage
  190.  
  191. function display-groups{
  192.    if ($NyVMRadButton.Checked -eq $true){
  193.        $TeamNameText.Visible=$true
  194.        $TeamTextBox.Visible=$true
  195.        $ExistingTeamList.Visible=$false
  196.        $ExistingTeamNameText.Visible=$false
  197.    }
  198.    if ($ExistingVMRadButton.Checked -eq $true){
  199.        $TeamNameText.Visible=$false
  200.        $TeamTextBox.Visible=$false
  201.        $ExistingTeamList.Visible=$true
  202.        $ExistingTeamNameText.Visible=$true
  203.  
  204.    }
  205. }    
  206.    $DeployVMGroup = New-Object System.Windows.Forms.groupBox #create the group box
  207.        $DeployVMGroup.Location = New-Object System.Drawing.Size(5,5) #location of the group box (px) in relation to the primary window's edges (length, height)
  208.        $DeployVMGroup.size = New-Object System.Drawing.Size(300,40) #the size in px of the group box (length, height)
  209.        $DeployVMGroup.text = "Options:" #labeling the box
  210.        $DeployVMPage.Controls.Add($DeployVMGroup) #activate the group box
  211.        
  212.  
  213.          
  214.    $NyVMRadButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  215.        $NyVMRadButton.Location = new-object System.Drawing.Point(5,15) #location of the radio button(px) in relation to the group box's edges (length, height)
  216.        $NyVMRadButton.size = New-Object System.Drawing.Size(95,20) #the size in px of the radio button (length, height)
  217.        $NyVMRadButton.Checked = $true #is checked by default
  218.        $NyVMRadButton.Text = "New Team" #labeling the radio button
  219.        $NyVMRadButton.Add_Click({display-groups})        
  220.        $DeployVMGroup.Controls.Add($NyVMRadButton) #activate the inside the group box
  221.          
  222.    $TeamNameText = New-Object System.Windows.Forms.Label
  223.        $TeamNameText.Text="TeamName"
  224.        $TeamNameText.Top="70"
  225.        $TeamNameText.Left="10"
  226.        $TeamNameText.Visible=$true
  227.        $TeamNameText.Anchor="Left,Top"
  228.        $TeamNameText.Size = New-Object System.Drawing.Size(250,15)
  229.        $DeployVMPage.Controls.Add($TeamNameText)
  230.    
  231.    $TeamTextBox = New-Object System.Windows.Forms.TextBox
  232.        $TeamTextBox.Text=""
  233.        $TeamTextBox.Top="85"
  234.        $TeamTextBox.Left="10"
  235.        $TeamTextBox.Anchor="Left,Top"
  236.        $TeamNameText.Visible=$true
  237.        $TeamTextBox.Size = New-Object System.Drawing.Size(150,23)
  238.        $DeployVMPage.Controls.Add($TeamTextBox)  
  239.  
  240.    $ExistingVMRadButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  241.        $ExistingVMRadButton.Location = new-object System.Drawing.Point(120,15) #location of the radio button(px) in relation to the group box's edges (length, height)
  242.        $ExistingVMRadButton.size = New-Object System.Drawing.Size(120,20) #the size in px of the radio button (length, height)
  243.        $ExistingVMRadButton.Checked = $false #is checked by default
  244.        $ExistingVMRadButton.Text = "Existing team" #labeling the radio button
  245.        $ExistingVMRadButton.Add_Click({display-groups})
  246.        $DeployVMGroup.Controls.Add($ExistingVMRadButton) #activate the inside the group box
  247.        
  248.  
  249.    $ExistingTeamNameText = New-Object System.Windows.Forms.Label
  250.        $ExistingTeamNameText.Text="Chose Team"
  251.        $ExistingTeamNameText.Top="70"
  252.        $ExistingTeamNameText.Left="10"
  253.        $ExistingTeamNameText.Visible=$false
  254.        $ExistingTeamNameText.Anchor="Left,Top"
  255.        $ExistingTeamNameText.Size = New-Object System.Drawing.Size(250,15)
  256.        $DeployVMPage.Controls.Add($ExistingTeamNameText)
  257.    
  258.    $VMListe=get-VMFolder
  259.        $ExistingTeamList = New-Object System.Windows.Forms.ComboBox
  260.        $ExistingTeamList.Text=""
  261.        $ExistingTeamList.Top="85"
  262.        $ExistingTeamList.Left="10"
  263.        $ExistingTeamList.Anchor="Left,Top"
  264.        $ExistingTeamList.Visible=$false
  265.        $ExistingTeamList.Size = New-Object System.Drawing.Size(150,23)
  266.        foreach ($item in $VMListe) {
  267.            $ExistingTeamList.Items.Add($item)
  268.        }
  269.        $DeployVMPage.Controls.Add($ExistingTeamList)
  270.                  
  271.    $TemplateTekst = New-Object System.Windows.Forms.Label
  272.        $TemplateTekst.Text="Template"
  273.        $TemplateTekst.Top="115"
  274.        $TemplateTekst.Left="10"
  275.        $TemplateTekst.Anchor="Left,Top"
  276.        $TemplateTekst.Size = New-Object System.Drawing.Size(100,15)
  277.        $DeployVMPage.Controls.Add($TemplateTekst)
  278.  
  279.    $TListe = Get-VMTemplates
  280.    $TemplateListe = New-Object System.Windows.Forms.ComboBox
  281.        $TemplateListe.Text=""
  282.        $TemplateListe.Top="130"
  283.        $TemplateListe.Left="10"
  284.        $TemplateListe.Anchor="Left,Top"
  285.        $TemplateListe.Size = New-Object System.Drawing.Size(150,23)
  286.        foreach ($item in $TListe) {
  287.            $TemplateListe.Items.Add($item)
  288.        }
  289.        $DeployVMPage.Controls.Add($TemplateListe)
  290.  
  291.    $GruppeTekst = New-Object System.Windows.Forms.Label
  292.        $GruppeTekst.Text="Number of Grps"
  293.        $GruppeTekst.Top="160"
  294.        $GruppeTekst.Left="10"
  295.        $GruppeTekst.Anchor="Left,Top"
  296.        $GruppeTekst.Size = New-Object System.Drawing.Size(110,15)
  297.        $DeployVMPage.Controls.Add($GruppeTekst)
  298.        
  299.    $AntalTextBox = New-Object System.Windows.Forms.TextBox
  300.        $AntalTextBox.Text=""
  301.        $AntalTextBox.Top="175"
  302.        $AntalTextBox.Left="10"
  303.        $AntalTextBox.Anchor="Left,Top"
  304.        $AntalTextBox.Size = New-Object System.Drawing.Size(50,23)
  305.        $DeployVMPage.Controls.Add($AntalTextBox)
  306.        
  307.  
  308.  
  309.    $DeployVMButton = New-Object System.Windows.Forms.Button
  310.        $DeployVMButton.Text="Deploy VM's"
  311.        $DeployVMButton.Top="200"
  312.        $DeployVMButton.Left="10"
  313.        $DeployVMButton.Anchor="Left,Top"
  314.        $DeployVMButton.Size = New-Object System.Drawing.Size(200,23)
  315.        $DeployVMButton.Add_Click({DeployVM})
  316.        $DeployVMPage.Controls.Add($DeployVMButton)
  317.  
  318.  
  319. #VM Management Page
  320. function do-stuffs{
  321.    if ($StartVMRadButton.Checked -eq $true) {Start-VMs}
  322.    if ($StopVMRadButton.Checked -eq $true) {Stop-VMs}
  323.    if ($RemoveVMRadButton.Checked -eq $true) {Remove-VMFolder}
  324.    }
  325.    
  326.    $VMManText = New-Object System.Windows.Forms.Label
  327.        $VMManText.Text="Chose Team"
  328.        $VMManText.Top="10"
  329.        $VMManText.Left="10"
  330.        $VMManText.Anchor="Left,Top"
  331.        $VMManText.Size = New-Object System.Drawing.Size(250,23)
  332.        $VMManagementPage.Controls.Add($VMManText)
  333.  
  334.    $VMListe=get-VMFolder
  335.    $VMManListe = New-Object System.Windows.Forms.ComboBox
  336.        $VMManListe.Text=""
  337.        $VMManListe.Top="35"
  338.        $VMManListe.Left="10"
  339.        $VMManListe.Anchor="Left,Top"
  340.        $VMManListe.Size = New-Object System.Drawing.Size(150,23)
  341.        foreach ($item in $VMListe) {
  342.            $VMManListe.Items.Add($item)
  343.        }
  344.        $VMManagementPage.Controls.Add($VMManListe)
  345.  
  346.  
  347.  
  348.    $VMManGroup = New-Object System.Windows.Forms.groupBox #create the group box
  349.        $VMManGroup.Location = New-Object System.Drawing.Size(10,70) #location of the group box (px) in relation to the primary window's edges (length, height)
  350.         $VMManGroup.size = New-Object System.Drawing.Size(200,120) #the size in px of the group box (length, height)
  351.         $VMManGroup.text = "Options:" #labeling the box
  352.         $VMManagementPage.Controls.Add($VMManGroup) #activate the group box
  353.    
  354.        
  355.     $StartVMRadButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  356.         $StartVMRadButton.Location = new-object System.Drawing.Point(5,25) #location of the radio button(px) in relation to the group box's edges (length, height)
  357.         $StartVMRadButton.size = New-Object System.Drawing.Size(150,20) #the size in px of the radio button (length, height)
  358.         $StartVMRadButton.Checked = $false #is checked by default
  359.         $StartVMRadButton.Text = "Start VMs" #labeling the radio button
  360.         $VMManGroup.Controls.Add($StartVMRadButton) #activate the inside the group box
  361.  
  362.     $StopVMRadButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  363.         $StopVMRadButton.Location = new-object System.Drawing.Point(5,50) #location of the radio button(px) in relation to the group box's edges (length, height)
  364.         $StopVMRadButton.size = New-Object System.Drawing.Size(150,20) #the size in px of the radio button (length, height)
  365.         $StopVMRadButton.Checked = $false #is checked by default
  366.         $StopVMRadButton.Text = "Stop VMs" #labeling the radio button
  367.         $VMManGroup.Controls.Add($StopVMRadButton) #activate the inside the group box
  368.  
  369.     $RemoveVMRadButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  370.         $RemoveVMRadButton.Location = new-object System.Drawing.Point(5,75) #location of the radio button(px) in relation to the group box's edges (length, height)
  371.         $RemoveVMRadButton.size = New-Object System.Drawing.Size(150,20) #the size in px of the radio button (length, height)
  372.         $RemoveVMRadButton.Checked = $false #is checked by default
  373.         $RemoveVMRadButton.Text = "Fjern VMs" #labeling the radio button
  374.         $VMManGroup.Controls.Add($RemoveVMRadButton) #activate the inside the group box
  375.  
  376.     $DoStuffVMButton = New-Object System.Windows.Forms.Button
  377.         $DoStuffVMButton.Text="Manage VMs"
  378.         $DoStuffVMButton.Top="200"
  379.         $DoStuffVMButton.Left="10"
  380.         $DoStuffVMButton.Anchor="Left,Top"
  381.         $DoStuffVMButton.Size = New-Object System.Drawing.Size(200,23)
  382.         $DoStuffVMButton.Add_Click({do-stuffs})
  383.         $VMManagementPage.Controls.Add($DoStuffVMButton)
  384.  
  385.  
  386.  
  387.          
  388. #VM Info Page
  389.  
  390.     $VMInfoTeamText = New-Object System.Windows.Forms.Label
  391.         $VMInfoTeamText.Text="Chose Team"
  392.         $VMInfoTeamText.Top="10"
  393.         $VMInfoTeamText.Left="10"
  394.         $VMInfoTeamText.Anchor="Left,Top"
  395.         $VMInfoTeamText.Size = New-Object System.Drawing.Size(250,23)
  396.         $VMInfoPage.Controls.Add($VMInfoTeamText)
  397.  
  398.     $VMInfoList = New-Object System.Windows.Forms.ComboBox
  399.         $VMInfoList.Text=""
  400.         $VMInfoList.Top="35"
  401.         $VMInfoList.Left="10"
  402.         $VMInfoList.Anchor="Left,Top"
  403.         $VMInfoList.Size = New-Object System.Drawing.Size(150,23)
  404.         foreach ($item in $VMListe) {
  405.             $VMInfoList.Items.Add($item)
  406.         }
  407.         $VMInfoPage.Controls.Add($VMInfoList)
  408.  
  409.  
  410.     $VMInfoGroup = New-Object System.Windows.Forms.groupBox #create the group box
  411.         $VMInfoGroup.Location = New-Object System.Drawing.Size(10,70) #location of the group box (px) in relation to the primary window's edges (length, height)
  412.         $VMInfoGroup.size = New-Object System.Drawing.Size(200,120) #the size in px of the group box (length, height)
  413.         $VMInfoGroup.text = "Options:" #labeling the box
  414.         $VMInfoPage.Controls.Add($VMInfoGroup) #activate the group box
  415.    
  416.        
  417.     $FilNavnRadioButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  418.         $FilNavnRadioButton.Location = new-object System.Drawing.Point(5,25) #location of the radio button(px) in relation to the group box's edges (length, height)
  419.         $FilNavnRadioButton.size = New-Object System.Drawing.Size(150,20) #the size in px of the radio button (length, height)
  420.         $FilNavnRadioButton.Checked = $false #is checked by default
  421.         $FilNavnRadioButton.Text = "~/Desktop/{INPUT}.txt" #labeling the radio button
  422.         $VMInfoGroup.Controls.Add($FilNavnRadioButton) #activate the inside the group box
  423.  
  424.     $VMInfoTextBox = New-Object System.Windows.Forms.TextBox
  425.         $VMInfoTextBox.Text=""
  426.         $VMInfoTextBox.Top="50"
  427.         $VMInfoTextBox.Left="5"
  428.         $VMInfoTextBox.Anchor="Left,Top"
  429.         $VMInfoTextBox.Size = New-Object System.Drawing.Size(190,120)
  430.         $VMInfoGroup.Controls.Add($VMInfoTextBox)
  431.  
  432.     $DefaultRadioButton = New-Object System.Windows.Forms.RadioButton #create the radio button
  433.         $DefaultRadioButton.Location = new-object System.Drawing.Point(5,90) #location of the radio button(px) in relation to the group box's edges (length, height)
  434.         $DefaultRadioButton.size = New-Object System.Drawing.Size(250,30) #the size in px of the radio button (length, height)
  435.         $DefaultRadioButton.Checked = $true #is checked by default
  436.         $DefaultRadioButton.Text = "Default ~/Desktop/{TEAMNAME}.txt" #labeling the radio button
  437.         $VMInfoGroup.Controls.Add($DefaultRadioButton) #activate the inside the group box
  438.  
  439.     $VMInfoButton = New-Object System.Windows.Forms.Button
  440.         $VMInfoButton.Text="Get VM Info"
  441.         $VMInfoButton.Top="200"
  442.         $VMInfoButton.Left="10"
  443.         $VMInfoButton.Anchor="Left,Top"
  444.         $VMInfoButton.Size= New-Object System.Drawing.Size(200,20)
  445.         $VMInfoButton.Add_Click({get-VMStats})
  446.         $VMInfoPage.Controls.Add($VMInfoButton)
  447.  
  448.  
  449. #Save the initial state of the form
  450. $InitialFormWindowState = $form1.WindowState
  451. #Init the OnLoad event to correct the initial state of the form
  452. $form1.add_Load($OnLoadForm_StateCorrection)
  453. #Show the Form
  454. $form1.ShowDialog()| Out-Null
  455. } #End function CreateForm
  456.  
  457.  
  458. CreateForm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement