Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 180329

Get clusters, display in pop box code issue

$
0
0

Hi ,

I know this is quite simple, but I am not sure how to fix it. When I retrieve the cluster names from vcenter, and there is only 1 cluster, the popup box is blank. Would someone please help me get this code to show the cluster if there is only one?
Thanks!

 

 

$v = get-cluster
$vcount = ($v).count
if ($vcount -lt 1 )
{
$vcount = "1"
}
$vchoice = " "

 

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

 

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "User Input Required:"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"

 

$objForm.KeyPreview = $True

 

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {
        foreach ($objItem in $objListbox.SelectedItems)
            {$vchoice += $objItem}
        $objForm.Close()
    }
    })

 

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
    {$objForm.Close()}})

 

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"

 

$OKButton.Add_Click(
   {
        foreach ($objItem in $objListbox.SelectedItems)
            {$vchoice += $objItem}
        $objForm.Close()
   })

 

$objForm.Controls.Add($OKButton)

 

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close(); $cancel= $true })
$objForm.Controls.Add($CancelButton)

 

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please choose a cluster:"
$objForm.Controls.Add($objLabel)

 

$objListbox = New-Object System.Windows.Forms.Listbox
$objListbox.Location = New-Object System.Drawing.Size(10,40)
$objListbox.Size = New-Object System.Drawing.Size(260,20)

 

$objListbox.SelectionMode = "MultiExtended"

 

#Foreach item in array display

 


for ($i=0;$i -lt $vcount; $i++) {

 

[void] $objListbox.Items.Add($v[$i]) }

 

$objListbox.Height = 70
$objForm.Controls.Add($objListbox)
$objForm.Topmost = $True

 

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()

 

$cancel


Viewing all articles
Browse latest Browse all 180329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>