Make Graph Reports with PowerShell for Exchange 2010 and ActiveSync

PowerShell is a fantastic tool to administrate our servers, we use it every day. In this article, you will learn how to use it to receive better information on your servers by creating Graph reports with PowerShell scripts.

This guide, written by Arnaud Buonaccorsi, will be based on PowerShell V3 and Exchange 2010 while focusing on ActiveSync. If you didn’t read Arnaud’s previous post, “PowerShell Tip: Easily Manage all of Your BYOD Devices”, check it out!

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. 

# 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. We have a lot of devices and we are ready to create rules to authorize some of them and deny others. First, we need to know which devices are on our servers and how many of each type (of course we already know that we have a LOT of Apple Devices).

The data will be organized into a list of ActiveSync devices, saying how many devices are on each type:

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

Then we’ll push the data onto our 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, we will generate the Chart as an image file. 

# 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


About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top