Saturday, September 19, 2009

Read Chad Miller’s blog entry on using MSChart from PowerShell. This is another great visualization extension for PowerShell. To make it work:

  • Download and install Microsoft Chart Controls for Microsoft .NET Framework 3.5
  • Download LibraryChart
  • The easiest way to enable it is to import the library with a call to ‘Import-Module’. Now run one of the samples:

    If you see this error or one like it it’s an easy fix. Edit the lib and edit the input param list in the function “New-Chart” from this:

    param ([int]$width,[int]$height,[int]$left,[int]$top,$chartTitle)

    To this:

    param ([int]$width,[int]$height,[int]$left,[int]$top,[string]$chartTitle)

    Voila. Re-import the module and the error is gone. The only item on my wish list for this lib is that it attempt to infer the X and Y fields. A call like this, for example, should be able to (but can’t) infer that xField is ‘name’ and yField is ‘ws’:

    ps | Sort-Object WS | select name, ws -first 5 | out-chart

    It makes eye-candy. Check this one out. Grab the top 5 memory consuming processes and push them into a relative pie chart that auto-updates itself.

    out-chart -chartType ‘pie’ -xField ‘name’ -yField ‘WS’ -scriptBlock { Get-Process | Sort-Object -Property WS | Select-Object Name,WS -Last 5}