Visual Studio 从Powershell脚本在DataGridView中显示输出

icnyk63a  于 2023-03-19  发布在  Shell
关注(0)|答案(1)|浏览(144)

我想在从powershell脚本运行的DataGridView中显示输出:

$domain1Groups     = (Get-ADuser -identity $var_userName.Text -server domain1 -Properties MemberOf).MemberOf -Replace 'CN=', '' -Replace ',.*', ''
$domain2Groups     = (Get-ADuser -identity $var_userName.Text -server domain2 -Properties MemberOf).MemberOf -Replace 'CN=', '' -Replace ',.*', ''
$domain3Groups     = (Get-ADuser -identity $var_userName.Text -server domain3 -Properties MemberOf).MemberOf -Replace 'CN=', '' -Replace ',.*', ''

使用这个脚本,我在powershell中得到一个列表,其中1列包含该域的所有成员。
尝试使用.ItemsSource,但在DataGridView中看不到任何内容

$var_comboBox.Add_SelectionChanged({


    $item = $var_comboBox.SelectedItem.Content

        if ($item -eq "domain1")
            {$var_DataGridView.ItemsSource = $domain1Groups



    }elseif
           ($item -eq "domain2" )
            {$var_DataGridView.ItemsSource = "$domain2Groups"

}


      else{
           ($item -eq "domain3" )
            $var_DataGridView.ItemSource = "$domain3Groups"

}})

I also want a customized Column that displays the text "Member Of"
mcvgt66p

mcvgt66p1#

如果像这样定义DataGrid

<DataGrid Name="dataGrid" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="Member Of" Binding="{Binding}" IsReadOnly="True" />
    </DataGrid.Columns>
</DataGrid>

...您应该能够如下设置ItemsSource属性:

$domain1Groups = (Get-ADuser ...
$dataGrid.ItemsSource = $domain1Groups

相关问题