以这段代码为例,该函数使用 vsphere cmd-let 根据列表框中选定的 VM 检索 CPU 编号。输出正在另一个列表框中工作,但我希望能够将结果输出到标签
function fill_updatelistbox
{
$vmlist1 = Get-vm -Name $listBox1.SelectedItem | select NumCPU
foreach ($vm1 in $vmlist1)
{
$label1.Text($vm1.NumCPU)
}
}
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 400
$System_Drawing_Point.Y = 115
$label1.Location = $System_Drawing_Point
$label1.Name = "label1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 100
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 0
$label1.Text = ""
编辑:下面的代码使用列表框工作
function fill_updatelistbox
{
$vmlist1 = Get-vm -Name $listBox1.SelectedItem | select NumCPU
foreach ($vm1 in $vmlist1)
{
[void]$listBox2.Items.Add($vm1.NumCPU)
}
}
$tabPage2.Controls.Add($panel2)
$listBox2.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox2.FormattingEnabled = $True
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 1
$System_Drawing_Point.Y = 1
$listBox2.Location = $System_Drawing_Point
$listBox2.Name = "listBox2"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 369
$System_Drawing_Size.Width = 160
$listBox2.Size = $System_Drawing_Size
$listBox2.TabIndex = 0
$panel2.Controls.Add