Advertisement
Guest User

Untitled

a guest
Sep 11th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.15 KB | None | 0 0
  1. #========================================================================
  2. # Tested on Powershell 5.0, PowerCli 6.3, vSphere 6.0, Windos 2003, Windows 2008, Windows 2012
  3. #----------------------------------------------
  4. #region Application Functions
  5. #----------------------------------------------
  6. function OnApplicationLoad {
  7. if(-not (Get-PSSnapin VMware.VimAutomation.Core)){
  8. Add-PSSnapin vmware.vimautomation.core -ErrorAction SilentlyContinue | Out-Null
  9. }
  10. return $true #return true for success or false for failure
  11. }
  12. function OnApplicationExit {
  13. if ($global:DefaultVIServers.Count -gt 0){
  14. Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
  15. $script:ExitCode = 0 #Set the exit code for the Packager
  16. }
  17. }
  18. #endregion Application Functions
  19. #----------------------------------------------
  20. # Generated Form Function
  21. #----------------------------------------------
  22. function Call-VMDiskDetails {
  23. #----------------------------------------------
  24. #region Import the Assemblies
  25. #----------------------------------------------
  26. [void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  27. [void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  28. [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  29. [void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  30. [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  31. [void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  32. [void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  33. [void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
  34. [void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
  35. #endregion Import Assemblies
  36. #----------------------------------------------
  37. #region Generated Form Objects
  38. #----------------------------------------------
  39. [System.Windows.Forms.Application]::EnableVisualStyles()
  40. $FormVMDiskDetails = New-Object 'System.Windows.Forms.Form'
  41. $buttonListDisk = New-Object 'System.Windows.Forms.Button'
  42. $comboboxVMs = New-Object 'System.Windows.Forms.ComboBox'
  43. $labelPassword = New-Object 'System.Windows.Forms.Label'
  44. $labelUserName = New-Object 'System.Windows.Forms.Label'
  45. $labelvCDetails = New-Object 'System.Windows.Forms.Label'
  46. $labelGuestDetails = New-Object 'System.Windows.Forms.Label'
  47. $labelgPassword = New-Object 'System.Windows.Forms.Label'
  48. $labelgUserName = New-Object 'System.Windows.Forms.Label'
  49. $labelVCenterOrESXi = New-Object 'System.Windows.Forms.Label'
  50. $chkPassthough = New-Object 'System.Windows.Forms.CheckBox'
  51. $labelIncreasedDiskSize = New-Object 'System.Windows.Forms.Label'
  52. $labelVirtualMachines = New-Object 'System.Windows.Forms.Label'
  53. $txtboxIncreaseDiskSize = New-Object 'System.Windows.Forms.NumericUpDown'
  54. $buttonLogin = New-Object 'System.Windows.Forms.Button'
  55. $buttonIncrease = New-Object 'System.Windows.Forms.Button'
  56. $username = New-Object 'System.Windows.Forms.TextBox'
  57. $maskedtextbox1 = New-Object 'System.Windows.Forms.MaskedTextBox'
  58. $gusername = New-Object 'System.Windows.Forms.TextBox'
  59. $gmaskedtextbox1 = New-Object 'System.Windows.Forms.MaskedTextBox'
  60. $vCenterOrEsxi = New-Object 'System.Windows.Forms.TextBox'
  61. $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
  62. $dataGrid1 = New-Object System.Windows.Forms.DataGridView
  63. $checkBox1 = New-Object System.Windows.Forms.CheckBox
  64. $chkPassthough = New-Object System.Windows.Forms.CheckBox
  65. $chkPassthoughW = New-Object System.Windows.Forms.CheckBox
  66. $StatusBar = New-Object System.Windows.Forms.StatusBar
  67. #endregion Generated Form Objects
  68. #----------------------------------------------
  69. # User Generated Script
  70. #----------------------------------------------
  71. function OnApplicationLoad {
  72. Add-PSSnapin VMware.VimAutomation.Cloud
  73. Add-PSSnapin vmware.vimautomation.core
  74. return $true #return true for success or false for failure
  75. }
  76. function OnApplicationExit {
  77. Disconnect-VIServer * -Confirm:$false
  78. $script:ExitCode = 0 #Set the exit code for the Packager
  79. }
  80. $FormVMDiskDetails_Load={
  81. #TODO: Initialize Form Controls here
  82. }
  83. #region Control Helper Functions
  84. function Load-ComboBox
  85. {
  86. Param (
  87. [ValidateNotNull()]
  88. [Parameter(Mandatory=$true)]
  89. [System.Windows.Forms.ComboBox]$ComboBox,
  90. [ValidateNotNull()]
  91. [Parameter(Mandatory=$true)]
  92. $Items,
  93. [Parameter(Mandatory=$false)]
  94. [string]$DisplayMember,
  95. [switch]$Append
  96. )
  97. if(-not $Append)
  98. {
  99. $ComboBox.Items.Clear()
  100. }
  101. if($Items -is [Object[]])
  102. {
  103. $ComboBox.Items.AddRange($Items)
  104. }
  105. elseif ($Items -is [Array])
  106. {
  107. $ComboBox.BeginUpdate()
  108. foreach($obj in $Items)
  109. {
  110. $ComboBox.Items.Add($obj)
  111. }
  112. $ComboBox.EndUpdate()
  113. }
  114. else
  115. {
  116. $ComboBox.Items.Add($Items)
  117. }
  118. $ComboBox.DisplayMember = $DisplayMember
  119. }
  120. function IsThereText
  121. {
  122. if ($vCenterOrEsxi.Text.Length -ne 0)
  123. {
  124. $buttonLogin.Enabled = $true
  125. }
  126. else
  127. {
  128. $buttonLogin.Enabled = $false
  129. }
  130. }
  131. #endregion
  132. $picturebox1_Click={
  133. #TODO: Place custom script here
  134. }
  135. $chkPassthough_Click={
  136.             if ($chkPassthough.Checked)
  137.             {
  138.                 $username.Text = whoami
  139.                 $username.Enabled = $false
  140.                 $maskedtextbox1.Enabled = $false
  141.             }
  142.             else
  143.             {
  144.                 $username.Enabled = $true
  145.                 $maskedtextbox1.Enabled = $true
  146.             }
  147.       }
  148. $chkPassthoughW_Click={
  149.             if ($chkPassthoughW.Checked)
  150.             {
  151.                 $gusername.Text = whoami
  152.                 $gusername.Enabled = $false
  153.                 $gmaskedtextbox1.Enabled = $false
  154.             }
  155.             else
  156.             {
  157.                 $gusername.Enabled = $true
  158.                 $gmaskedtextbox1.Enabled = $true
  159.             }
  160.       }
  161. $buttonLogin_Click={
  162. #TODO: Place custom script here
  163. if ($vCenterOrEsxi.TextLength -ne 0)
  164.                 {
  165.                 Try { 
  166.                     $vCenterOrESXiName = $vCenterOrEsxi.Text
  167.                     $StatusBar.Text = "Connecting $vCenterOrESXiName..."
  168.                     if ($chkPassthough.Checked)
  169.                     {
  170.                         Connect-VIServer $vCenterOrEsxi.Text -ErrorAction SilentlyContinue | Out-Null
  171.                         $StatusBar.Text = "Connected $vCenterOrESXiName via Passthrough..."
  172.                    
  173.                     }
  174.                     else
  175.                     {
  176.                         Connect-VIServer $vCenterOrEsxi.Text -User $username.Text -Password $maskedtextbox1.Text -ErrorAction SilentlyContinue | Out-Null
  177.                         $StatusBar.Text = "Connected $vCenterOrESXiName with defined credentials..."
  178.                     }
  179. $VMs = Get-VM | Select-Object -ExpandProperty Name
  180. $VMs | ForEach-Object {Load-ComboBox -ComboBox $ComboBoxVMs -Append -Items $_}
  181.                     $comboboxVMs.Enabled = $true
  182.                     $buttonListDisk.Enabled = $true
  183.                
  184.                 } 
  185.                 Catch { 
  186.                     $error[0].Exception | Out-Null 
  187.                     $StatusBar.Text = "Unable to connect $vCenterOrESXiName, validate details and connectivity..."
  188.                     $comboboxVMs.Enabled = $false
  189.                     $buttonIncrease.Enabled = $false
  190.                 }
  191.             }
  192. }
  193. $comboboxVMs_SelectedIndexChanged={
  194. #TODO: Place custom script here
  195. }
  196. $dataGrid1_Click={
  197. $txtboxIncreaseDiskSize.Value = $dataGrid1.CurrentRow.Cells[4].Value
  198. if ($dataGrid1.CurrentRow.Cells[7].Value -eq "C:"){
  199. $checkBox1.Checked = $true
  200. }else {
  201. $checkBox1.Checked = $false
  202. }
  203. }
  204. $buttonIncrease_Click={
  205. if($txtboxIncreaseDiskSize.Value -gt $dataGrid1.CurrentRow.Cells[4].Value){
  206. Get-HardDisk -vm $ComboBoxVMs.SelectedItem.ToString() | where {$_.Name -eq $dataGrid1.CurrentRow.Cells[3].Value} | Set-HardDisk -CapacityGB $txtboxIncreaseDiskSize.Text -ResizeGuestPartition -GuestUser $gusername.Text -GuestPassword $gmaskedtextbox1.Text -Confirm:$false
  207. }
  208. }
  209. $buttonListDisk_Click={
  210. #TODO: Place custom script here
  211. $dataGrid1.Rows.Clear()
  212. $dataGrid1.Refresh()
  213. if($($ComboBoxVMs.SelectedItem.ToString() | measure).count){
  214. $gpassword = $gmaskedtextbox1.Text | ConvertTo-SecureString -AsPlainText -Force
  215. $GuestCredentials = new-object system.management.automation.PSCredential $gusername.Text,$gpassword
  216. #===
  217. #Change this as needed. Our standard display name is the hostname followed by a space...
  218. $VMView = Get-VM -Name $ComboBoxVMs.SelectedItem.ToString() | Get-View
  219.  
  220. $ServerDiskToVolume = @(
  221. Get-WmiObject -Class Win32_DiskDrive -ComputerName $VMView.Name -Credential $GuestCredentials | foreach {
  222. $Dsk = $_
  223. $query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_DiskPartition"
  224. Get-WmiObject -Query $query -ComputerName $VMView.Name -Credential $GuestCredentials | foreach {
  225. $query = "ASSOCIATORS OF {Win32_DiskPartition.DeviceID='$($_.DeviceID)'} WHERE ResultClass=Win32_LogicalDisk"
  226. Get-WmiObject -Query $query -ComputerName $VMView.Name -Credential $GuestCredentials | Select DeviceID,
  227. VolumeName,
  228. @{ label = "SCSITarget"; expression = {$dsk.SCSITargetId} },
  229. @{ label = "SCSIBus"; expression = {$dsk.SCSIBus} }
  230. }
  231. }
  232. )
  233. # Now loop thru all the SCSI controllers on the VM and find those that match the Controller and Target
  234. $VMDisks = ForEach ($VirtualSCSIController in ($VMView.Config.Hardware.Device | Where {$_.DeviceInfo.Label -match "SCSI Controller"}))
  235. {
  236. ForEach ($VirtualDiskDevice in ($VMView.Config.Hardware.Device | Where {$_.ControllerKey -eq $VirtualSCSIController.Key}))
  237. {
  238. #Match up this VM to a logical disk
  239. $MatchingDisk = @( $ServerDiskToVolume | Where {$_.SCSITarget -eq $VirtualDiskDevice.UnitNumber -and $_.SCSIBus -eq $VirtualSCSIController.BusNumber} )
  240. $DiskFileName = $VirtualDiskDevice.Backing.FileName
  241. $DSName = $DiskFileName.Split("]")[0].TrimStart("[")
  242. #Build a custom object to hold this. We use PS3 language...
  243. [pscustomobject]@{
  244. VMName = $VMView.Name
  245. HostName = $VMView.Guest.HostName
  246. PowerStatus = $VMView.Runtime.PowerState
  247. DiskFile = $VirtualDiskDevice.Backing.FileName
  248. DiskName = $VirtualDiskDevice.DeviceInfo.Label
  249. DiskSize = $VirtualDiskDevice.CapacityInKB / 1MB
  250. SCSIController = $VirtualSCSIController.BusNumber
  251. SCSITarget = $VirtualDiskDevice.UnitNumber
  252. DeviceID = $MatchingDisk.DeviceID
  253. DSFreeGB = Get-Datastore -Name $DSName | %{$_.FreeSpaceGB}
  254. }
  255. }
  256. }
  257. $VMDisks | foreach{$datagrid1.Rows.Add($_.VMName,$_.HostName,$_.PowerStatus,$_.DiskFile,$_.DiskName,$_.DiskSize,$_.SCSIController,$_.SCSITarget,$_.DeviceID,"{0:N2}" -f $_.DSFreeGB)}
  258. #
  259. #===
  260. $dataGrid1.AutoResizeColumns()
  261. $txtboxIncreaseDiskSize.Value = $dataGrid1.CurrentRow.Cells[4].Value
  262. if ($dataGrid1.CurrentRow.Cells[7].Value -eq "C:"){
  263. $checkBox1.Checked = $true
  264. }else {
  265. $checkBox1.Checked = $false
  266. }
  267. }
  268. $txtboxIncreaseDiskSize.Enabled = $true
  269. $buttonIncrease.Enabled = $true
  270. }
  271. $labelMessage_Click={
  272. #TODO: Place custom script here
  273. }
  274. # --End User Generated Script--
  275. #----------------------------------------------
  276. #region Generated Events
  277. #----------------------------------------------
  278. $Form_StateCorrection_Load=
  279. {
  280. #Correct the initial state of the form to prevent the .Net maximized form issue
  281. $FormVMDiskDetails.WindowState = $InitialFormWindowState
  282. }
  283. $Form_Cleanup_FormClosed=
  284. {
  285. #Remove all event handlers from the controls
  286. try
  287. {
  288. $buttonListDisk.remove_Click($buttonListDisk_Click)
  289. $comboboxVMs.remove_SelectedIndexChanged($comboboxVMs_SelectedIndexChanged)
  290. $buttonLogin.remove_Click($buttonLogin_Click)
  291. $FormVMDiskDetails.remove_Load($FormVMDiskDetails_Load)
  292. $FormVMDiskDetails.remove_Load($Form_StateCorrection_Load)
  293. $FormVMDiskDetails.remove_FormClosed($Form_Cleanup_FormClosed)
  294. }
  295. catch [Exception]
  296. { }
  297. }
  298. #endregion Generated Events
  299. #----------------------------------------------
  300. #region Generated Form Code
  301. #----------------------------------------------
  302. #
  303. # FormDiskIncrease
  304. #
  305. $FormVMDiskDetails.Controls.Add($buttonListDisk)
  306. $FormVMDiskDetails.Controls.Add($comboboxVMs)
  307. $FormVMDiskDetails.Controls.Add($labelPassword)
  308. $FormVMDiskDetails.Controls.Add($labelUserName)
  309. $FormVMDiskDetails.Controls.Add($labelgPassword)
  310. $FormVMDiskDetails.Controls.Add($labelgUserName)
  311. $FormVMDiskDetails.Controls.Add($labelVCenterOrESXi)
  312. $FormVMDiskDetails.Controls.Add($buttonLogin)
  313. $FormVMDiskDetails.Controls.Add($buttonIncrease)
  314. $FormVMDiskDetails.Controls.Add($username)
  315. $FormVMDiskDetails.Controls.Add($maskedtextbox1)
  316. $FormVMDiskDetails.Controls.Add($gusername)
  317. $FormVMDiskDetails.Controls.Add($gmaskedtextbox1)
  318. $FormVMDiskDetails.Controls.Add($labelIncreasedDiskSize)
  319. $FormVMDiskDetails.Controls.Add($labelVirtualMachines)
  320. $FormVMDiskDetails.Controls.Add($txtboxIncreaseDiskSize)
  321. $FormVMDiskDetails.Controls.Add($vCenterOrEsxi)
  322. $FormVMDiskDetails.Controls.Add($dataGrid1)
  323. $FormVMDiskDetails.Controls.Add($checkBox1)
  324. $FormVMDiskDetails.Controls.Add($chkPassthough)
  325. $FormVMDiskDetails.Controls.Add($chkPassthoughW)
  326. $FormVMDiskDetails.Controls.Add($StatusBar)
  327. $FormVMDiskDetails.Controls.Add($labelvCDetails)
  328. $FormVMDiskDetails.Controls.Add($labelGuestDetails)
  329. $FormVMDiskDetails.ClientSize = '1100, 700'
  330. #
  331. $FormVMDiskDetails.Name = "FormDiskIncrease"
  332. $FormVMDiskDetails.StartPosition = "CenterScreen"
  333. $FormVMDiskDetails.AutoSizeMode = "GrowOnly"
  334. $FormVMDiskDetails.Text = "Virtual Machine Disk Increase - By Sudarshan Bharti"
  335. $FormVMDiskDetails.add_Load($FormVMDiskDetails_Load)
  336. #
  337. # buttonListDisk
  338. #
  339. $buttonListDisk.Location = '362, 148'
  340. $buttonListDisk.Name = "buttonListDisk"
  341. $buttonListDisk.Size = '90, 23'
  342. $buttonListDisk.TabIndex = 14
  343. $buttonListDisk.Enabled = $false
  344. $buttonListDisk.Text = "List &Disks"
  345. $buttonListDisk.UseVisualStyleBackColor = $True
  346. $buttonListDisk.add_Click($buttonListDisk_Click)
  347. #
  348. # StatusBar
  349. #
  350. $StatusBar.Name = "StatusBar"
  351. $StatusBar.Size = '95, 23'
  352. $StatusBar.TabIndex = 20
  353. $StatusBar.Text = "Enter vCenter and Credentials..."
  354. $StatusBar.ShowPanels = $false
  355. #
  356. # buttonIncrease
  357. #
  358. $buttonIncrease.Location = '692, 148'
  359. $buttonIncrease.Name = "buttonIncrease"
  360. $buttonIncrease.Size = '90, 23'
  361. $buttonIncrease.TabIndex = 18
  362. $buttonIncrease.Enabled = $false
  363. $buttonIncrease.Text = "&IncreaseDisk"
  364. $buttonIncrease.UseVisualStyleBackColor = $True
  365. $buttonIncrease.add_Click($buttonIncrease_Click)
  366. #
  367. # comboboxVMs
  368. #
  369. $comboboxVMs.FormattingEnabled = $True
  370. $comboboxVMs.Location = '13, 148'
  371. $comboboxVMs.Name = "comboboxVMs"
  372. $comboboxVMs.Size = '318, 23'
  373. $comboboxVMs.TabIndex = 13
  374. $comboboxVMs.Enabled = $false
  375. $comboboxVMs.add_SelectedIndexChanged($comboboxVMs_SelectedIndexChanged)
  376. #
  377. # labelPassword
  378. #
  379. $labelPassword.Location = '12, 91'
  380. $labelPassword.Name = "labelPassword"
  381. $labelPassword.Size = '100, 23'
  382. $labelPassword.TabIndex = 6
  383. $labelPassword.Text = "&Password"
  384. #
  385. # labelUserName
  386. #
  387. $labelUserName.Location = '12, 65'
  388. $labelUserName.Name = "labelUserName"
  389. $labelUserName.Size = '100, 23'
  390. $labelUserName.TabIndex = 4
  391. $labelUserName.Text = "&UserName"
  392. #
  393. # labelvCDetails
  394. #
  395. $labelvCDetails.Location = '90, 10'
  396. $labelvCDetails.Name = "labelvCDetails"
  397. $labelvCDetails.Size = '250, 23'
  398. $labelvCDetails.TabIndex = 13
  399. $labelvCDetails.Text = "&vCenter Details"
  400. $labelvCDetails.Font = New-Object System.Drawing.Font("Arial",12,[System.Drawing.FontStyle]::Bold)
  401. #
  402. # labelGuestDetails
  403. #
  404. $labelGuestDetails.Location = '662, 10'
  405. $labelGuestDetails.Name = "labelGuestDetails"
  406. $labelGuestDetails.Size = '250, 23'
  407. $labelGuestDetails.TabIndex = 13
  408. $labelGuestDetails.Text = "Guest &Credentials"
  409. $labelGuestDetails.Font = New-Object System.Drawing.Font("Arial",12,[System.Drawing.FontStyle]::Bold)
  410. #
  411. # labelgPassword
  412. #
  413. $labelgPassword.Location = '562, 65'
  414. $labelgPassword.Name = "labelgPassword"
  415. $labelgPassword.Size = '100, 23'
  416. $labelgPassword.TabIndex = 14
  417. $labelgPassword.Text = "&Guest Password"
  418. #
  419. # labelgUserName
  420. #
  421. $labelgUserName.Location = '562, 39'
  422. $labelgUserName.Name = "labelgUserName"
  423. $labelgUserName.Size = '100, 23'
  424. $labelgUserName.TabIndex = 14
  425. $labelgUserName.Text = "Gu&est UserName"
  426. #
  427. # labelIncreasedDiskSize
  428. #
  429. $labelIncreasedDiskSize.Location = '562, 125'
  430. $labelIncreasedDiskSize.Name = "labelIncreasedDiskSize"
  431. $labelIncreasedDiskSize.Size = '130, 23'
  432. $labelIncreasedDiskSize.TabIndex = 16
  433. $labelIncreasedDiskSize.Text = "I&ncreased Disk Size"
  434. #
  435. # labelVirtualMachine
  436. #
  437. $labelVirtualMachines.Location = '12, 125'
  438. $labelVirtualMachines.Name = "labelVirtualMachine"
  439. $labelVirtualMachines.Size = '100, 23'
  440. $labelVirtualMachines.TabIndex = 12
  441. $labelVirtualMachines.Text = "Virtual &Machines"
  442. #
  443. # txtboxIncreaseDiskSize
  444. #
  445. $txtboxIncreaseDiskSize.Location = '565, 148'
  446. $txtboxIncreaseDiskSize.Name = "txtboxIncreaseDiskSize"
  447. $txtboxIncreaseDiskSize.Size = '60, 23'
  448. $txtboxIncreaseDiskSize.TabIndex = 17
  449. $txtboxIncreaseDiskSize.Increment = 1
  450. $txtboxIncreaseDiskSize.Enabled = $false
  451. $txtboxIncreaseDiskSize.Maximum = 2048
  452. $txtboxIncreaseDiskSize.Minimum = 1
  453. #
  454. # labelVCenterOrESXi
  455. #
  456. $labelVCenterOrESXi.Location = '12, 39'
  457. $labelVCenterOrESXi.Name = "labelVCenterOrESXi"
  458. $labelVCenterOrESXi.Size = '100, 23'
  459. $labelVCenterOrESXi.TabIndex = 1
  460. $labelVCenterOrESXi.Text = "&vCenter or ESXi"
  461. #
  462. # buttonLogin
  463. #
  464. $buttonLogin.Location = '892, 91'
  465. $buttonLogin.Name = "buttonLogin"
  466. $buttonLogin.Size = '89, 23'
  467. $buttonLogin.TabIndex = 11
  468. $buttonLogin.Text = "&Login"
  469. $buttonLogin.Enabled = $false
  470. $buttonLogin.UseVisualStyleBackColor = $True
  471. $buttonLogin.add_Click($buttonLogin_Click)
  472. #
  473. # username
  474. #
  475. $username.Location = '127, 65'
  476. $username.Name = "username"
  477. $username.Size = '204, 23'
  478. $username.TabIndex = 5
  479. $username.Text = whoami
  480.       $username.Enabled = $false
  481.       $maskedtextbox1.Enabled = $false
  482. #
  483. # maskedtextbox1
  484. #
  485. $maskedtextbox1.Location = '127, 91'
  486. $maskedtextbox1.Name = "maskedtextbox1"
  487. $maskedtextbox1.Size = '204, 23'
  488. $maskedtextbox1.TabIndex = 7
  489. $maskedtextbox1.UseSystemPasswordChar = $True
  490. #
  491. # gusername
  492. #
  493. $gusername.Location = '662, 39'
  494. $gusername.Name = "username"
  495. $gusername.Size = '204, 23'
  496. $gusername.TabIndex = 9
  497. $gusername.Text = whoami
  498.       $gusername.Enabled = $false
  499.       $gmaskedtextbox1.Enabled = $false
  500. #
  501. # gmaskedtextbox1
  502. #
  503. $gmaskedtextbox1.Location = '662, 65'
  504. $gmaskedtextbox1.Name = "maskedtextbox1"
  505. $gmaskedtextbox1.Size = '204, 23'
  506. $gmaskedtextbox1.TabIndex = 10
  507. $gmaskedtextbox1.UseSystemPasswordChar = $True
  508. #
  509. # vCenterOrEsxi
  510. #
  511. $vCenterOrEsxi.Location = '127, 39'
  512. $vCenterOrEsxi.Name = "&vCenterOrEsxi"
  513. $vCenterOrEsxi.Size = '204, 23'
  514. $vCenterOrEsxi.TabIndex = 2
  515. $vCenterOrEsxi.add_TextChanged({IsThereText})
  516. #
  517. # dataGrid1
  518. #
  519. $dataGrid1.Location = '13, 180'
  520. $dataGrid1.Name = "dataGrid1"
  521. $dataGrid1.Size = '1070, 497'
  522. $dataGrid1.TabIndex = 15
  523. $dataGrid1.MultiSelect = $false
  524. $dataGrid1.SelectionMode = 'FullRowSelect'
  525. $dataGrid1.AllowUserToAddRows = $false
  526. $dataGrid1.AllowUserToDeleteRows = $false
  527. $dataGrid1.AllowUserToOrderColumns = $true
  528. $dataGrid1.ReadOnly = $true
  529. $dataGrid1.AllowUserToResizeColumns = $false
  530. $dataGrid1.AllowUserToResizeRows = $false;
  531. $dataGrid1.ColumnCount = 10
  532. $dataGrid1.ColumnHeadersVisible = $true
  533. $dataGrid1.Columns[0].Name = "VMName"
  534. $dataGrid1.Columns[1].Name = "HostName"
  535. $dataGrid1.Columns[2].Name = "PowerStatus"
  536. $dataGrid1.Columns[3].Name = "DiskFile"
  537. $dataGrid1.Columns[4].Name = "DiskName"
  538. $dataGrid1.Columns[5].Name = "DiskSize"
  539. $dataGrid1.Columns[6].Name = "SCSIController"
  540. $dataGrid1.Columns[7].Name = "SCSITarget"
  541. $dataGrid1.Columns[8].Name = "DeviceID"
  542. $dataGrid1.Columns[9].Name = "DSFreeGB"
  543. $dataGrid1.add_Click($dataGrid1_Click)
  544. #
  545. # checkBox1
  546. #
  547. $checkBox1.Location = '990, 148'
  548. $checkBox1.Name = "checkBox1"
  549. $checkBox1.Size = '204, 23'
  550. $checkBox1.TabIndex = 18
  551. $checkBox1.Text = "System Partition"
  552. $checkBox1.Enabled = $false
  553.       # chkPassthough 
  554.       # 
  555.       $chkPassthough.Location = '360, 39' 
  556.       $chkPassthough.Name = "chkPassthough" 
  557.       $chkPassthough.Text = "&Use Windows Login"
  558.       $chkPassthough.TabIndex = 3
  559.       $chkPassthough.Size = '200, 23'
  560.       $chkPassthough.UseVisualStyleBackColor = $True
  561.       $chkPassthough.Checked = $True
  562.       $chkPassthough.add_Click($chkPassthough_Click)
  563.       # chkPassthoughW
  564.       # 
  565.       $chkPassthoughW.Location = '892, 39' 
  566.       $chkPassthoughW.Name = "chkPassthoughW" 
  567.       $chkPassthoughW.Text = "Use &Windows Login"
  568.       $chkPassthoughW.TabIndex = 8
  569.       $chkPassthoughW.Size = '200, 23'
  570.       $chkPassthoughW.UseVisualStyleBackColor = $True
  571.       $chkPassthoughW.Checked = $True
  572.       $chkPassthoughW.add_Click($chkPassthoughW_Click)
  573. #endregion Generated Form Code
  574. #----------------------------------------------
  575. #Save the initial state of the form
  576. $InitialFormWindowState = $FormVMDiskDetails.WindowState
  577. #Init the OnLoad event to correct the initial state of the form
  578. $FormVMDiskDetails.add_Load($Form_StateCorrection_Load)
  579. #Clean up the control events
  580. $FormVMDiskDetails.add_FormClosed($Form_Cleanup_FormClosed)
  581. #Show the Form
  582. return $FormVMDiskDetails.ShowDialog()
  583. } #End Function
  584. #Call OnApplicationLoad to initialize
  585. if((OnApplicationLoad) -eq $true)
  586. {
  587. #Call the form
  588. Call-VMDiskDetails | Out-Null
  589. #Perform cleanup
  590. OnApplicationExit
  591. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement