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:
[void][Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms.DataVisualization”) $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.
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:
Next, we will generate the Chart as an image file.
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: