GSX Blog

Create Graph Reports with PowerShell for Exchange 2010 and ActiveSync

Posted by Arnaud Buonaccorsi on Mon, Aug 19, 2013

exchange2010powershellactivesync resized 600PowerShell is a fantastic tool to administrate our servers. I use it every day. However, I would like to use it to receive better information on my servers. So today I will show you how to create Graph reports with PowerShell scripts.

My guide will be based on PowerShell V3 and Exchange 2010. I’m still focused on ActiveSync (if you didn’t read my previous post, make sure to read it!).

The first step is to have Microsoft Chart Controls for Microsoft .NET Framework 3.5. If you have the .NET framework v4.x installed on your PC, you already have all you need. For .NET v3.5 Sp1, you can install MCCs as an ‘add-on’. To get the installation package, click here.

To begin, declare your assembly and create the chart. You can set the size of your chart as well as the background color:

$chart1 = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$chart1.Width = 800
$chart1.Height = 300
$chart1.BackColor = [System.Drawing.Color]::White

Then you need to set the title with the position, the typo and your axis settings. After this step, we will focus on the data :

# title
   [void]$chart1.Titles.Add("ActiveSync Devices per type")
   $chart1.Titles[0].Font = "Arial,13pt"
   $chart1.Titles[0].Alignment = "topLeft"
# chart area
   $chartarea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
   $chartarea.Name = "ChartArea1"
   $chartarea.AxisY.Title = "Number of devices"
   $chartarea.AxisX.Title = "Devices types"
   $chartarea.AxisY.Interval = 1
   $chartarea.AxisX.Interval = 1
# legend
   $legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
   $ = "Legend1"

Now let’s start with the data. In this post, I need to get a report on my ActiveSync devices. I have a lot of devices and I’m ready to create rules to authorize some of them and deny others. First of all, I need to know which devices are on my servers and how many on each type (of course I already know I have a LOT of Apple Devices).

My data will be organized into a list of ActiveSync devices, telling me how many devices are on each type:

# data source    $datasource = Get-ActiveSyncDevice | select devicemodel | Group-Object devicemodel

Then I will push the data into my charts:

# data series
   $chart1.Series["DevicesAS"].ChartType = "Column"
   $chart1.Series["DevicesAS"].BorderWidth  = 3
   $chart1.Series["DevicesAS"].IsVisibleInLegend = $true
   $chart1.Series["DevicesAS"].chartarea = "ChartArea1"
   $chart1.Series["DevicesAS"].Legend = "Legend1"
   $chart1.Series["DevicesAS"].color = "#62B5CC"
   $datasource | ForEach-Object {$chart1.Series["DevicesAS"].Points.addxy( $ , $_.count) } 

Next, I will generate the Chart as an image file. Of course I could continue my script to send the picture as email attachment, but that’s a whole other story… ;)

# save chart

As you can see, it is not too complex to create a graph with PowerShell. Now you can create graphs and publish them on Exchange, SharePoint, etc.

And finally, here is the end result of the script:

activesync devices resized 600

Thinking of trying it out? Let me know about your experience in the comments below!


If you haven't tried GSX' solutions yet, why not sign up for a free 14-day trial or request a personal demo.

Tags: Exchange 2010, Microsoft, Exchange, ActiveSync, Powershell