/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Windows "Monad" Shell (MSH) Beta 3.1 "," Windows "Monad" Shell (MSH) Beta 3.1 "," scripting games Last Day MSH answers for event 7 a... "," Scripting Games almost over "," The Scripting Games Event 6 in MSH "," Scripting Games week 2 "," Monad Links "," MSH Concentration (scripting games part 4) "," scripting games part 3 "," 2006 Winter Scripting Games (part 2) "," ")

Tuesday, February 28, 2006


out-dataGrid function for Monad

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


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
    $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)" 

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.


Greetings /\/\o\/\/
Tags :

Blogger Sung Meister
Woo wee, the form is displayed on TOP of MSH console! :) BTW, "new" isn't aliased inside the function~

I haven't thought about using "DataGrid" to display member information. I wrote a very similar cmdlet that utilizes "PropertyGrid", instead

function Get-GuiMember ($object) {
trap { break; }

$obj = $object
if ($object -eq $null) { $obj = $input }

[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null
$form = new-object System.Windows.Forms.Form

$pg = new-object System.Windows.Forms.PropertyGrid
$pg.Dock = [System.Windows.Forms.DockStyle]"Fill"
$pg.SelectedObject = $obj

$form = $null;

Well, try out something like

MSH>get-guimember pwd
MSH>get-guimember (pwd)
MSH>get-guimember ls
MSH>get-guimember (ls)

Even better, try this out
MSH>$f = ls InstallUtil.InstallLog
MSH>get-guimember $f

Now then, using the PropertyGrid, you can modify some of the attributes of the file $f...

Anyways, I think i will try to modify my script a bit to make it show above MSH console :)
Blogger /\/\o\/\/
I started my blog with that script ;-)


gr /\/\o\/\/
Blogger Sung Meister
oy, oy, I wonder why I have missed that blog post.. *sigh*.. I was totally trying to reinvent the wheel. :)
Blogger /\/\o\/\/
@dbmws, I think we all do that in Monad (and fun it is :-))
I redid this one from a Q&D .NET snippet I made 3 years ago.

b.t.w. that script got me mentioned on the video : More talking about Monad on channel 9


see also :


so I will not forget !
I love hearing JS about it ;-)
(@ 26 Min I think, at that time I knew it by second LOL)

but as you showed, it could use some revisiting, I justed started then.(could not do pipeline ;-))

I was thinking for sometime already that I should do that,
Today I also noticed that the WMI method help script was "broken" in Beta 3. I posted the fixes in the NG but want to look at the series of scripts a bit more,
..if you have any suggestions.. feel free to comment ;-)

greetings /\/\o\/\/
Blogger /\/\o\/\/
and the $topmost in all GUI scripts

and recently I found a copy and paste error (everything on one line) in an old post also, that missed in cleaning up.

but it is so hard to fix in the blogger interface
Post a Comment

<< Home


October 2005   November 2005   December 2005   January 2006   February 2006   March 2006   April 2006   May 2006   June 2006   July 2006   August 2006   September 2006   October 2006   November 2006   December 2006  

$Links = ("PowerShell RC1 Docs"," PowerShell RC1 X86"," PowerShell RC1 X64"," Monad GettingStarted guide"," Monad Progamming Guide"," Monad SDK"," Monad videos on Channel 9"," MSH Community Workspace"," scripts.readify.net "," MonadSource"," www.reskit.net"," PowerShell Blog"," Under The Stairs"," computerperformance powershell Home"," proudlyserving"," MSH on wikipedia"," MSHWiki Channel 9"," Keith Hill's Blog"," Precision Computing"," PowerShell for fun"," MSH Memo (Japanese)"," monadblog")

find-blog -about "PowerShell","Monad" | out-Technorati.
find-blog -contains "","" | out-Technorati.
Web mow001.blogspot.com

This page is powered by Blogger. Isn't yours?