[英]How to populate Combobox with result of Powershell command
Can someone assist on how to fill a combobox with the result of a powershell command?有人可以协助如何使用 powershell 命令的结果填充组合框吗?
Im trying to fill a combobox with the result of a "Get" cmdlet but I only get some powershell parameters as result.我试图用“获取”cmdlet 的结果填充组合框,但结果我只得到了一些 powershell 参数。
$ButtonCollectionSearch.Add_Click({
$name = $textboxlogonname.text
$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.Width = 400
$Collections = Get-RDSessionCollection | fl -Property CollectionName
Foreach ($Collection in $Collection) {
$ComboBox.Items.Add($Collection);
}
$ComboBox.Location = New-Object System.Drawing.Point(120, 10)
$main_form.Controls.Add($ComboBox)
})
The reason you're getting formatting metadata is that you asked for formatting metadata - by piping all your data through fl
(which is a alias for Format-List
).您获取格式化元数据的原因是您要求格式化元数据 - 通过通过
fl
(这是Format-List
的别名)传输所有数据。
Since we just want the value of the CollectionName
, use ForEach-Object -MemberName
in place of fl -Property
:因为我们只想要
CollectionName
的值,所以使用ForEach-Object -MemberName
代替fl -Property
:
$Collections = Get-RDSessionCollection | ForEach-Object -MemberName CollectionName
You'll also want to address the typo in the foreach
loop declaration - change:您还需要解决
foreach
循环声明中的拼写错误 - 更改:
Foreach ($Collection in $Collection) {
to:到:
Foreach ($Collection in $Collections) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.