PowerShell 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:
[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. After this step, we will focus on the data :
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:
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… ;)
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:
Thinking of trying it out? Let me know about your experience in the comments below!