将PS对象数组作为列表框中的项目传递

时间:2019-01-23 17:20:55

标签: powershell

如果我有这样的事情:

$applications = @();

$applications += New-Object PSObject -property @{Name = "MyApp1"; 
ServerName = "SBDEVSQL";}

$applications += New-Object PSObject -property @{Name = "MyApp2"; ServerName = 
"SSQL2016";}

,如果我有类似gui的列表框:

$lblDbTableInApp = New-Object system.Windows.Forms.Label
$lblDbTableInApp.text = "Application tables"
$lblDbTableInApp.AutoSize = $true
$lblDbTableInApp.width = 25     $lblDbTableInApp.height = 10
$lblDbTableInApp.location = New-Object System.Drawing.Point(312, 242)
$lblDbTableInApp.Font = 'Microsoft Sans Serif,10'

如何将我的项目作为我的$ applications数组中的项目(仅显示名称)传递给该列表框,同时还要在内存中保留其他属性? 也许:

lblDbTableInApp.DataSource = $applications #but I don't know how to preview only the Name, but to keep other props in memory, for future calls..

0 个答案:

没有答案