Monday, January 19, 2009

display data with DataGrid

to tabulate a list of all services by sorting the services by their state before filling the datagrid, then output the processes

PS>
[void][System.reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$form = new-object System.Windows.Forms.Form
$DataGridView = new-object System.windows.forms.DataGridView
$Form.Text = "My First Datagrid"
$array= new-object System.Collections.ArrayList

$array.AddRange( @( get-service | write-output ) )
// $array.AddRange( @( get-process | sort-object company | write-output ) )

$DataGridView.DataSource = $array
$DataGridView.Dock = "fill"
$DataGridView.AllowUsertoResizeColumns=$True
$form.Controls.Add($DataGridView)
$form.showdialog()


For Get-Service cmdlet, the column headers in datagrid shows (Name, CanPauseAndContinue, CanShutdown, CanStop, DisplayName, ServiceName, Status)

For Get-Process cmdlet, the column headers in datagrid shows ( _NounName, Name, Handles, VM, WS, PM, NPM, Path, Company, CPU, FileVersion, ProductVersion, Description, Product, BasePriority, HandleCount, Id, etc. ) or, get-process | fl *

No comments:

Post a Comment