I'm new to the world of building PowerShell GUI's with Sapien and am looking for some help to do with comboboxes please if anyone has some time...
I've built a basic GUI which uses VMware PowerCLI to pull a list of our "Datastores" into a combobox. The aim is for the user to select their desired "Datastore" from the populated list, and the "FreeSpaceGB" will be displayed below.
I've managed to get it working (to an extent) - but, the issue I'm having is that when I change the "Datastore" in the combobox, the "FreeSpaceGB" doesn't change. You'll see from the attached pictures, datastore BUILD-A-01 has 172.79GB Freespace, but changing to BUILD-A-02 does nothing to the FreeSpaceGB value.
Code:
Code: Select all
Connect-VIServer Build
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '200,200'
$Form.text = "Datastore"
$Form.TopMost = $false
$Form.AutoSize = $true
$Form.BackColor = "#717074"
$Form.ForeColor = "#ffffff"
$DatastoreLabel = New-Object system.Windows.Forms.Label
$DatastoreLabel.text = "Datastore..."
$DatastoreLabel.AutoSize = $true
$DatastoreLabel.width = 150
$DatastoreLabel.height = 30
$DatastoreLabel.location = New-Object System.Drawing.Point(20,100)
$DatastoreLabel.ForeColor = "#ffffff"
$DatastoreLabel.Font = '10'
$DatastoreCombo = New-Object system.Windows.Forms.ComboBox
$DatastoreCombo.text = ""
$DatastoreCombo.width = 150
$DatastoreCombo.height = 30
$DatastoreCombo.BackColor = "#ffffff"
$DatastoreCombo.ForeColor = "#717074"
$DatastoreCombo.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
@(Get-Datastore | Sort) | ForEach-Object {[void] $DatastoreCombo.Items.Add($_)}
$DatastoreCombo.location = New-Object System.Drawing.Point(20,150)
$DatastoreCombo.SelectedIndex = 0
$OutputLabel = New-Object System.Windows.Forms.Label
$OutputLabel.text = "$(Get-Datastore $Datastore.SelectedItem.ToString() | Format-List -Property FreeSpaceGB | Out-String)"
$OutputLabel.width = 300
$OutputLabel.height = 300
$OutputLabel.location = New-Object System.Drawing.Point(20,200)
$Form.controls.AddRange(@($DatastoreLabel,$DatastoreCombo,$OutputLabel))
[void]$Form.ShowDialog()
Thanks, Waddo2018