PowerShell, put XML into DataGrid
I would like to populate DataGrid with XML data stored in variable.
Below I have working example of populating DataGrid.
$grid = New-Object System.Windows.Forms.DataGrid
$array = New-Object System.Collections.ArrayList
foreach ($e in $(Get-Process | Select Name,Company)) { $array.Add($e) 开发者_JS百科}
$grid.DataSource = $array
How can I do it easily to load XML data into ArrayList?
I tried ReadXml but it displays only one expandable node in Grid.
I need to display data the same as Get-Process gives me.
Maybe there is some other solution?
Regards.
Load the XML into a DataSet and bind it to a DataGridView control.
Add-Type -AssemblyName System.Windows.Forms
$ds = New-Object System.Data.Dataset
$null = $ds.ReadXml('d:\users.xml')
$grid = New-Object System.Windows.Forms.DataGridView
$grid.DataSource = $ds.Tables[0].DefaultView
$grid.DataBind()
精彩评论