从Powershell中的多个下拉列表返回多个值

从Powershell中的多个下拉列表返回多个值,powershell,dropdown,Powershell,Dropdown,我对powershell是个新手。我的任务是创建一个GUI,它从多个下拉列表中接收多个字符串,并根据这些选择重命名计算机。我用两个选项测试它,$FacilityInitials和$BuildingNumber。Powershell仅返回$BuildingNumber选项 我回来可能有问题吧?我应该如何正确地执行多个返回功能?谢谢!:) 我试着检查打字错误 #Edit This item to change the DropDown Values [array]$DropDownArray1 =

我对powershell是个新手。我的任务是创建一个GUI,它从多个下拉列表中接收多个字符串,并根据这些选择重命名计算机。我用两个选项测试它,$FacilityInitials和$BuildingNumber。Powershell仅返回$BuildingNumber选项

我回来可能有问题吧?我应该如何正确地执行多个返回功能?谢谢!:)

我试着检查打字错误

#Edit This item to change the DropDown Values

[array]$DropDownArray1 = "LI", "BE", "HA"

# This Function Returns the Selected Value and Closes the Form

function Return-DropDown {
$script:Choice = $DropDown1.SelectedItem.ToString()
$Form.Close()
}

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


$Form = New-Object System.Windows.Forms.Form

$Form.width = 350
$Form.height = 200
$Form.Text = ”Computer Renamer”

$DropDown1 = new-object System.Windows.Forms.ComboBox
$DropDown1.Location = new-object System.Drawing.Size(100,30)
$DropDown1.Size = new-object System.Drawing.Size(130,30)

ForEach ($Item in $DropDownArray1) {
[void] $DropDown1.Items.Add($Item)
}

$Form.Controls.Add($DropDown1)

$DropDown1Label = new-object System.Windows.Forms.Label
$DropDown1Label.Location = new-object System.Drawing.Size(10,30) 
$DropDown1Label.size = new-object System.Drawing.Size(100,20) 
$DropDown1Label.Text = "Facility Initials:"
$Form.Controls.Add($DropDown1Label)

################################################################################

#Edit This item to change the DropDown Values

[array]$DropDownArray2 = "01", "02", "03"

# This Function Returns the Selected Value and Closes the Form

function Return-DropDown {
$script:Choice2 = $DropDown2.SelectedItem.ToString()
$Form.Close()
}

$DropDown2 = new-object System.Windows.Forms.ComboBox
$DropDown2.Location = new-object System.Drawing.Size(100,60)
$DropDown2.Size = new-object System.Drawing.Size(130,30)

ForEach ($Item in $DropDownArray2) {
[void] $DropDown2.Items.Add($Item)
}

$Form.Controls.Add($DropDown2)

$DropDown2Label = new-object System.Windows.Forms.Label
$DropDown2Label.Location = new-object System.Drawing.Size(10,60) 
$DropDown2Label.size = new-object System.Drawing.Size(100,20) 
$DropDown2Label.Text = "Building Number:"
$Form.Controls.Add($DropDown2Label)

################################################################################

#Button

$Button = new-object System.Windows.Forms.Button
$Button.Location = new-object System.Drawing.Size(100,130)
$Button.Size = new-object System.Drawing.Size(150,20)
$Button.Text = "Rename Computer"
$Button.Add_Click({Return-DropDown})
$form.Controls.Add($Button)

################################################################################


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

$FacilityInitials = $Choice
$BuildingNumber = $Choice2

$newCompName = $FacilityInitials + "-" + $BuildingNumber

$AdminAcc = ""

#Add Restart and Force later

Rename-Computer -NewName $newCompName -DomainCredential $AdminAcc

组合框
不支持多选,请使用
列表框
,如果这是一个新项目,我建议使用WPF。它将更易于维护,并且有一个交互式编辑器,可以通过Visual Studio为您提供xml定义。@MathiasR.Jessen谢谢!成功实现了基于
列表框
的GUI。
组合框
不支持多选,请使用
列表框
,如果这是一个新项目,我建议使用WPF。它将更易于维护,并且有一个交互式编辑器,可以通过Visual Studio为您提供xml定义。@MathiasR.Jessen谢谢!成功实现了基于
列表框的GUI。