我尝试输入数组对象 $WinRoles(从远程主机获取WindowsFeature)。需要将 $WinRoles.DisplayName 和 $WinRoles.InstallState 作为表插入到文本框 $TextBoxInstalledRolesFeatures 中
下面我的代码(这是出现此问题的代码部分),我缺少哪里?
<#------======== Label Installed Roles&Features ========------#>
$LabelInstalledRolesFeatures = New-Object System.Windows.Forms.Label
$LabelInstalledRolesFeatures.Location = '810,10'
$LabelInstalledRolesFeatures.AutoSize = $true
$LabelInstalledRolesFeatures.Text = 'Installed Roles and Features'
$CommonForm.Controls.Add($LabelInstalledRolesFeatures)
<#------======== Label Installed Roles&Features ========------#>
<#------======== TextBox Installed Roles&Features ========------#>
$TextBoxInstalledRolesFeatures = New-Object System.Windows.Forms.ListBox
$TextBoxInstalledRolesFeatures.Location = '810,30'
$TextBoxInstalledRolesFeatures.Size = '250,316'
$TextBoxInstalledRolesFeatures.Text = ''
$CommonForm.Controls.Add($TextBoxInstalledRolesFeatures)
<#------======== TextBox Installed Roles&Features ========------#>
<#------======== Button Show Roles&Features ========------#>
$ButtonShowRolesFeatures = New-Object System.Windows.Forms.Button
$ButtonShowRolesFeatures.Location = '985, 5'
$ButtonShowRolesFeatures.Text = 'Show'
$ButtonShowRolesFeatures.AutoSize = $true
$ButtonShowRolesFeatures.add_Click({
$SelectedServer = $ListboxListeServers.SelectedItem
$Session = New-PSSession -ComputerName $SelectedServer
$WinRoles = Invoke-Command -Session $Session -ScriptBlock {
Get-WindowsFeature | where Installed -eq $true
}
[array]$AllRoles = $WinRoles | select DisplayName, InstallState
$TextBoxInstalledRolesFeatures.Text = $AllRoles
})
$CommonForm.Controls.Add($ButtonShowRolesFeatures)
<#------======== Button Show Roles&Features ========------#>
1条答案
按热度按时间mitkmikd1#
你应该使用
DataGridView
而不是ListBox
,就像评论中推荐的Mathias一样。这个实现并不复杂,是你用例的理想控件。我的笔记本电脑里没有Get-WindowsFeature
,但作为一个例子,这里有一个使用Get-Process
作为网格数据源的实现: