That’s a nice descriptive title isn’t it, but that is exactly what we are going to accomplish here. The end result that we are going for it is an HTML formatted email with a table that gives us a listing of all devices registered to Active Sync (device model and general device type), the account they are associated with, first connection, most recent connection. The actual info that is used in your report can be customized but this is a good starting point.
We’ll just start off with my default disclaimer and now move right on to the work.
A couple things I am going to assume are…This script is actually running on an Exchange server so it has direct access to the Exchange PS tools. I am also going to assume that you have read my previous post about making an HTML formatted email report from PS.
Here is our starting point, because we don’t want to waste time looking through all the mailboxes we are using the Get-CASMailbox command here with the filter to identify only mailboxes that have a device associated by them. The second line creates a new array that is eventually populated with all that device info.
Now this section is where we are going to get into the heavy lifting. What is happening ere is that we are stepping through that list of mailboxes that have devices associated and running a Get-MailboxDeviceStatistics against it and storing it briefly in a variable. With all the info specific to that device, storing it in a variable, we then loop again through that variable. This time we create a PS Object to act as a row in the array we created earlier. In creating that row we are going to put our info under some logical header names and them add that object/row to the array with that $MobileDeviceInfo += $row.
At this point the data is gathered and an email can be generated and sent. Rather than sending a generic email though, lets step it up with a little formatting and styling. The variable $WeekAgo is storing the date from one week ago and that is going to be used to highlight any device that is new within a week or has not done a sync in a week. I use 1 week because I have this report run every Friday but it could be any time frame.
The code in these 2 images are actually in one block but are separate here to make it easier. Together they make up the the actual HTML and data in the report. In the top image is the creation of the layout of the HTML table and a little static info. We also add the CSS in the HTML tags to help make it look “pretty” and a little more readable.
Once the columns are laid out the data has to be entered and that is coming in as a loop. We are creating a table so each step through the loop is going to make a row. HTML is inside the loop to create the row and format it as its populating.
From there we just close up the HTML and run the Send-Message command and wait a second to marvel in awe at the clean user friendly data.