在文本框 WindowsForm 中输入数组对象

问题描述 投票:0回答:0

我尝试输入数组对象 $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 ========------#>
arrays powershell input textbox windows-forms-designer
© www.soinside.com 2019 - 2024. All rights reserved.