Get clusters, display code pop box problem

Hello

I know it's pretty simple, but I don't know how to fix it. When I retrieve the names of cluster of vcenter, and there is only 1 cluster, the popup box is empty. Could someone please help me get this code to display the cluster if there is one?
Thank you!

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

[Sub] [System.Reflection.Assembly]: LoadWithPartialName ("System.Windows.Forms")
[Sub] [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 to $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 to $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 select 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 in table view


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

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

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

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

$cancel

When there is only 1 cluster, the $v variable is not an array, and the Count property does not exist (as long as you do not use PowerShell v3).

What you can do is to change this line in

$v = @(get-cluster)

In this way, there will be a table, even with 1 cluster.

For any cluster ($v - eq $null) you need to add additional lines.

Tags: VMware

Similar Questions

Maybe you are looking for