Tasty Technology! By Tim Scarfe.

Tuesday, November 21, 2006 - 00:27 [#]

PowerGadgets Rocks!



If you love Powershell as much as I do; stop what you are doing (after reading this entire blog entry of course) and check out the trial of PowerGadgets.


"PowerGadgets is a revolutionary new data visualization product that utilizes Windows PowerShell, Microsofts new scripting shell, to allow the creation of Gadgets in Windows XP, Windows Vista, Windows Server 2003 and Windows Server "Longhorn". PowerGadgets requires no complex development environments, servers or browsers to run real-time Gadget components such as charts, gauges and maps on your desktop or in the Windows Sidebar."


I discovered it after watching Jeremy Snover (Powershell Architect) demonstrate it during an IIS7 admin Channel9 video.


Summing up grossly; PowerGadgets gives you dash-boarding capability from the power you have in PS using several visualization "gadgets":


  • Chart (out-chart)
  • Gauge (out-gauge)
  • Map (out-map)

get-wmiobject Win32_PerfRawData_PerfOS_Memory | out-gauge -value AvailableMBytes -floating


Gives me this floating gadget on my desktop:



I can even get it to refresh every second, with this extension:


get-wmiobject Win32_PerfRawData_PerfOS_Memory | out-gauge -value AvailableMBytes -floating -Refresh 0:0:1

 

As a side note; there are millions of different styles for these gadgets, even a designer tool to let you create templates which you can reference on the cmd-lets with -template x.pgt


How about this one (display of top 20 processes, ordered descending by private bytes):


gps | sort PM -des | select Name, PM -fir 30 | out-chart



The seriously clever thing is that it can visualize anything you could possibly chuck at it i.e. imported CSV file, objects from Active Directory, the file system, anything!


Anyway I thought I would create a simple digital gauge displaying the ping time to www.dotnetsolutions.ltd.uk updating every second. Unfortunately because I was calling into a console application (.exe) I would get an annoying black box flick up every second.


#getping1.ps1

$pattern = New-Object System.Text.RegularExpressions.Regex "\d{1,4}ms"

$pattern.Match( ( ping ( args[0] +" -n 1" ) ) ).Value

#called with ./getping1.ps1 www.dotnetsolutions.ltd.uk | out-gauge


So the solution? Well I'm glad you asked!


#getping2.ps1


$pattern = New-Object System.Text.RegularExpressions.Regex "\d{1,4}ms"

$psi = New-Object System.Diagnostics.ProcessStartInfo "ping.exe", ( $args[0] + " -n 1" )

$psi.CreateNoWindow=1

$psi.RedirectStandardOutput = 1

$psi.UseShellExecute=0

$process = New-Object System.Diagnostics.Process

$process.StartInfo=$psi

$process.Start() | Out-Null

$process.WaitForExit()

$match = $pattern.Match( $process.StandardOutput.ReadToEnd() )

 

if( $match.Success ) {

$match.Value

}

else {

$args[0] +" is not responding to ICMP echo requests (pings)..."

}

 

No annoying black box on that one.


.\getping.ps1 www.dotnetsolutions.ltd.uk | out-gauge -Template GaugeTemplate.pgt -refresh 0:0:1



You can annotate the gadgets with titles so you know which is which. In Vista the gadgets can even live in the side bar!


Copyright Tim Scarfe © 1999-2006. All rights reserved.
Dot Net Solutions