This blog has moved to http://ThePowerShellGuy.com
Greetings /\/\o\/\/
This function will translate the input it gets from the pipeline to a dataTable and then shows it on a Form in a datagrid.
some examples to try :
ls | out-datagrid
gps | out-datagrid
ls function: select name,definition | out-datagrid
get-alias | out-datagrid
get-command | select name,definition | out-datagrid
get-help about_* | select name,synopsis | out-datagrid
get-wmiobject win32_share | select [a-z]* | out-datagrid
e.g.
the Funtion looks like this :
# Function out-datagrid
# shows piplineinput in datagrid
# /\/\o\/\/ 2006
# http:mow001.blogspot.com
Function out-dataGrid {
# Make DataTable from Input
$dt = new Data.datatable
$First = $true
foreach ($item in $input){
$DR = $DT.NewRow()
$Item.mshObject.get_properties() | foreach {
If ($first) {
$Col = new-object Data.DataColumn
$Col.ColumnName = $_.Name.ToString()
$DT.Columns.Add($Col) }
if ($_.value -eq $null) {
$DR.Item($_.Name) = "[empty]"
}
ElseIf ($_.IsArray) {
$DR.Item($_.Name) =[string]::Join($_.value ,";")
}
Else {
$DR.Item($_.Name) = $_.value
}
}
$DT.Rows.Add($DR)
$First = $false
}
# show Datatable in Form
$form = new-object Windows.Forms.form
$form.Size = new-object System.Drawing.Size @(1000,600)
$DG = new-object windows.forms.DataGrid
$DG.CaptionText = "Number of Rows $($DT.rows.Count)"
$DG.AllowSorting = $True
$DG.DataSource = $DT.mshobject.baseobject
$DG.Dock = [System.Windows.Forms.DockStyle]::Fill
$form.text = "$($myinvocation.line)"
$form.Controls.Add($DG)
$Form.Add_Shown({$form.Activate()})
$form.showdialog()
}
B.T.W. Note the different way to get the form topmost ($form.topmost = $true does not seem to work anymore in Beta3(.1)) but I think this one's better anyway.Enjoy,
Greetings /\/\o\/\/
Tags : Monad msh