아래의 코드는 각 폴더에 나열된 폴더와 특정 VM을 표시하는 데 완벽하게 작동합니다. 문제는 각 체크 박스에 대한 체크 상태를 찾으려고 할 때 발생합니다. 활성 UI가 나에게 좋은 체크 표시를 제공하지만, 처음에는 두 가지 일을하기 위해 참조 할 수있는 값/변수를 찾을 수 없습니다. 하나는 표시/해제하는 것입니다. 폴더가 선택/선택 해제되어있는 경우 각 VM 아래의 모든 VM, 원하는 경우 (이 경우에는 poweroff/poweron 지원이 포함됨) 실행됩니다.확인란의 실시간 상태를 어떻게 얻을 수 있습니까? PowerShell의 체크 박스 VM.checked?
크기에 관해서는 죄송합니다 - 확인란의 핵심 부분 만 원하면 확인란 영역에 있습니다. button1은 내가 체크 박스를 반복하면서 체크 박스를 능동적으로 제어하지 않기 때문에 어떤 체크 박스가 체크되었는지를 볼 수있게 해준다. 스크립트는 레이아웃에서 훌륭하게 작동하지만 체크 박스 또는 checkboxesVM의 상태를 얻기 위해 변수 참조를 찾을 수없는 것 같습니다. 아무도 내 UI에서이 작업을 수행하는 방법을 알 수 없으므로 목록 상자에서 활성 상태를보고 할 수 있습니까? 일단 내가 가지고 있으면 나는 내가 필요한 재료로 일할 수 있다고 생각한다.
$ServerList = Get-VM | Sort-Object -Property Folder,Name | `
?{$_.PowerState -eq "PoweredOn"}
$ServerCount= $ServerList.Count
$VMFolders = $ServerList | Group-Object folder
#----------------------------------------------
Function GenerateForm {
$handler_button1_Click= {
#Click Event Monitor
$listBox1.Items.Clear()
foreach($x in $checkboxes) {
$names = $x.name
$chkStat = $x.Checkstate
$status = $names+ " " +$chkStat
$listBox1.Items.Add("$status")
}
}
#end Click Event
$form1 = New-Object System.Windows.Forms.Form
$button1 = New-Object System.Windows.Forms.Button
$checkBoxes = New-Object System.Windows.Forms.CheckBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#region Generated Form Code
$Form1.Text = "VMWare VM Server Power On/Off"
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + "\powershell.exe")
$form1.icon=$icon
if($ServerCount -ge 6){
$Form1ShapeW = (1000)
if($ServerCount -ge 20){
$Form1ShapeH = ($ServerCount * 35)/5
} else {
$form1ShapeH = (120)
}
} else {
$Form1ShapeW = 100 + (155 * $ServerCount)
}
$System_Drawing_Size = New-Object System.Drawing.Size($Form1ShapeW,$Form1ShapeH)
$form1.ClientSize = $System_Drawing_Size
$form1.autosize = $true
#endregion
$x=5
$y=30
$i=0
$FX=100
$FY=$y
#region CheckBoxes
$Checkboxes = @()
$VMfolders | %{
$Checkboxes += New-Object System.Windows.Forms.CheckBox
$Checkboxes[-1].useVisualStyleBackColor = $true
$System_Drawing_Size = New-Object System.Drawing.Size(85,25)
$Checkboxes[-1].Size = $System_Drawing_Size
$Checkboxes[-1].text = $_.name
if($x -ge 200) {
$X = 5
$Y = $y + 27
$FY = $y
}
$System_Drawing_Point = New-Object System.Drawing.Point($x,$y)
$Checkboxes[-1].Location = $System_Drawing_Point
$Checkboxes[-1].DataBindings.DefaultDataSourceUpdateMode = 0
$Checkboxes[-1].name = "folder"
$y = $y + 27
#region CheckBoxesVM
$VMList = $_.Group
$CheckboxesVM = @()
$VMList | %{
$CheckboxesVM += New-Object System.Windows.Forms.CheckBox
$System_Drawing_Size = New-Object System.Drawing.Size(150,25)
$CheckboxesVM[-1].Size = $System_Drawing_Size
$CheckboxesVM[-1].text = $_
if($fx -ge 1000) {
$FX = 100
$FY = $FY + 25
}
$System_Drawing_Point = New-Object System.Drawing.Point($FX,$FY)
$CheckboxesVM[-1].Location = $System_Drawing_Point
$CheckboxesVM[-1].DataBindings.DefaultDataSourceUpdateMode = 0
$CheckboxesVM[-1].name = "server"
$FX = $FX + 155
$form1.Controls.Add($CheckboxesVM[-1])
$y=$FY + 27
}
$FX = 100
$FY = $FY + 27
#endregion checkboxesVM
$form1.Controls.Add($Checkboxes[-1])
}
#endregion Checkboxes
#region Buttons & Boxes
$button1.TabIndex = 1
$button1.Name = "button1"
$System_Drawing_Size = New-Object System.Drawing.Size(75,23)
$button1.Size = $System_Drawing_Size
$button1.UseVisualStyleBackColor = $True
$button1.Text = "Run Script"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 25
$z = if($y -ge $FY){
($y + 27) }
else {
($FY + 27)
}
$System_Drawing_Point.Y = $z
$button1.Location = $System_Drawing_Point
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$button1.add_Click($handler_button1_Click)
$form1.Controls.Add($button1)
$listBox1 = New-Object System.Windows.Forms.ListBox
$listBox1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size(400,60)
$listBox1.Size = $System_Drawing_Size
$listBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$listBox1.Name = "listBox1"
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = ($x+100)
$System_Drawing_Point.Y = $y
$listBox1.Location = $System_Drawing_Point
$form1.Controls.Add($listBox1)
}
#End GenerateForm Function
#Call the Function
GenerateForm
Sapien을 사용하고 있다고 가정 할 수 있습니까? –
'$ chkStat = $ x.Checkstate' 명령 대신에 ($ x.Checked -eq $ true) {$ chkStat = $ true} else {$ chkStat = $ false}'시도해보고 동작하는지 확인하십시오 다르게. –