/\/\o\/\/ PowerShelled

This blog has moved to http://ThePowerShellGuy.com Greetings /\/\o\/\/
$AtomFeed = ("Atom.xml")
$PreviousItems = (" Monad Release for Whidbey RTM "," Thow Dices in MSH "," when to change your clock ? ask Monad !! "," AD Infastructure exploring with MSH "," Get Current dir in MSH consoleTtitle "," MSH ASCII translator "," red MSH> prompt "," Monad presentation on PDC05 available, "," A guided tour of the MSH on arstechnica.com "," Lets Query WMI from MSH "," ")

Sunday, October 30, 2005

 


WMI viewer script for MSH (GUI)



I Like sometimes a quick overview of I WMI class,
the MSH script below adds the Function :

get-WMIDatagrid (GWD)

to MSH, with this function you can look at the Instances of a WMI Object in a Datagrid.
I will first grab all Instances of the Class and add all the properties to a DataTable.
then it will launce a form with a Datagrid linked to the Generated DataTable.
this gives you a quick overview of the Class and the instances.

for example :

MSH> GWD win32_share

gr /\/\o\/\/

PS as I get All the Data you can get problems with a few classes (for example the Eventlog) that have very much data in them.(but there are only a few of them)


# WmiDatagrid.msh
# Shows Instances of WMIClass in Datagrid
# /\/\o\/\/ 2005

[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")

function get-WMIDatagrid {
  Param ([string] $WmiClass = "")

  if ($wmiClass -eq "") {Throw "No WMIClass given"}

  $MC = new-object system.management.ManagementClass $wmiCLass
  $MOC = $MC.GetInstances()

  trap{"Class Not found";break}

  $DT =  new-object  System.Data.DataTable
  $DT.TableName = $wmiClass

  $i = 0
  $MOC | foreach {
    $MO = $_

    # Make a DataRow
    $DR = $DT.NewRow()

    $MO.get_properties() | foreach {

      $prop = $_

      If ($i -eq 0)  {
        # Only On First Row make The Headers

        $Col =  new-object System.Data.DataColumn
        $Col.ColumnName = $prop.Name.ToString()
        $prop.get_Qualifiers() | foreach {
          If ($_.Name.ToLower() -eq "key") {
            $Col.ColumnName = $Col.ColumnName + "*"
          }
        }
        $DT.Columns.Add($Col) 
      }

      #fill dataRow 

      if ($prop.value -eq $null) {
        $DR.Item($prop.Name) = "[empty]"
      }
      ElseIf ($prop.IsArray) {
        $DR.Item($prop.Name) =[string]::Join($prop.value ,";")
      }
      Else {
        $DR.Item($prop.Name) = $prop.value
        #Item is Key try again with *
        trap{$DR.Item("$($prop.Name)*") = $prop.Value.tostring();continue}
      }
    }
    # Add the row to the DataTable
    $DT.Rows.Add($DR)
    $i += 1
  }
   
  $form = new-object "System.Windows.Forms.Form"
  $form.Size = new-object System.Drawing.Size @(800,400)
  $DG = new-object "System.windows.forms.DataGrid"
  $DG.CaptionText = "$wmiClass $($DT.Count)"
  $DG.AllowSorting = $True
  $DG.DataSource = $DT.mshobject.baseobject
  $DG.Dock = [System.Windows.Forms.DockStyle]::Fill

  #show the Form

  $form.text = "$wmiCLass"
  $form.Controls.Add($DG)
  $form.topmost = $true
  $form.showdialog()
}

set-alias gwd get-WMIDatagrid



Comments: Post a Comment

Links to this post:

Create a Link



<< Home

Archives

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.
Google
 
Web mow001.blogspot.com

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