Creating graphs with Windows PowerShell

Joel Bennett (PowerShell MVP) has created a script module named PowerBoots, which makes it easier to create graphical user interfaces in PowerShell v2 (available as a snapin for PowerShell v1).

Project description for the PowerShell PowerBoots project on CodePlex:

PowerBoots makes it easier for scripters to create graphical user interfaces in PowerShell, exposing much of the power of WPF to PowerShell in a simple syntax which supports events, threading, and much, much, more.

PowerBoots is written as a script module which dynamically generates functions into static script files for each WPF control, combined with a compiled module called PoshWpf which was originally part of PoshConsole (and includes the Out-Wpf cmdlet and New-BootsWindow cmdlets among others) … the module enables threaded UIs as well as enabling support for styles, control templates and data templates.

Included in the PowerBoots script module are also the VisiFire Charts Package, a set of data visualization controls powered by Microsoft Silverlight and WPF.
This makes it possible to create graphs with Windows PowerShell, which Ill provide some examples on.
Before we move on to the examples, I would encourage you to go look at the PowerBoots site as well as the blog posts on PowerBoots on Joel
s  blog.

Creating graphs for Active Directory user accounts

The first example will get all users in the East Organizational Unit from a lab-domain:

image

It will then show the number of users per OU in a chart:

image

image

image

As you can see in the last graph, there are some animations available when you hover the mouse over a bar, it displays the number of users.
Its also possible to export the graphs to images, using Export-BootsImage. If you want to do that, remember to turn off animations by setting AnimationsEnabled equal to false, else the exported images wont display any graphs.

PowerShell code to generate a chart to show Active Directory users per OU:

#Import Active Directory-module
Import-Module ActiveDirectory

#Import PowerBoots-module
Import-Module PowerBoots

#Create graph
New-BootsWindow -Content {
Chart -Width 400 -Height 200 -Theme Theme3 (
DataSeries $(
$OUs = Get-ADOrganizationalUnit -SearchBase “OU=East,DC=contoso,DC=no” -SearchScope OneLevel -Filter * |
Select-Object Name,DistinguishedName
foreach ($OU in $OUs) {
$count = (Get-ADUser -Filter * -SearchBase $OU.DistinguishedName | Measure-Object).Count
DataPoint -YValue ($count) -AxisXLabel $OU.Name
}
) -RenderAs bar
)} -Title "Number of users per OU"

Note that you can control the look by customizing i.e. the “Theme” and “RenderAs” parameters.
Valid “RenderAs” parameters: Column, Line, Pie, Bar, Area, Doughnut, StackedColumn, StackedColumn100, StackedBar, StackedBar100, StackedArea, StackedArea100, Bubble, Point.

For a list of samples, I would encourage you to visit the VisiFire Charts Gallery.

Creating graphs for Microsoft Exchange mailboxes

This example will show the number of Exchange mailboxes per database:

image

image

image

PowerShell code to generate a chart to show Exchange mailboxes per database:

Creating graphs for Microsoft Exchange ActiveSync devices


The last example will show Exchange ActiveSync devices per type:

image

image

image

PowerShell code to generate a chart to show Exchange ActiveSync devices by type:

Note that this example will work against Exchange Server 2010. For working against Exchange 2007 you will need to take a different approach using Get-ActiveSyncDeviceStatistics, since the Get-ActiveSyncDevice cmdlet doesnt exist.

We ve looked at some examples of practical usage of the chart features available in PowerBoots and VisiFire, and as you can imagine, you may create graphs for whatever you would like to.
An example of practical usage in addition to the above examples would be to schedule a script which exports the charts to images using Export-BootsImage, and then copies the images to i.e. a webserver, which displays the images on the IT-department
s intranet.