Monday, March 10, 2014

Active Sync Device Reports

This post is just a quick reference to Active Sync report scripts which are available for Exchange 2007 and Exchange 2010/2013.  Exchange 2007 is a little different to pull reports as the Get-ActiveSyncDevice cmdlet does not exist, only the Get-ActiveSyncDeviceStatistics command exists on Exchange 2007.

On Exchange 2007, to quickly pull a CSV of ActiveSync activity including EmailAddress, DeviceType and LastSuccessSync, simply execute the following PowerShell command in an Exchange 2007 Exchange Management Shell:

Get-Mailbox -ResultSize:Unlimited | ForEach {Get-ActiveSyncDeviceStatistics -Mailbox:$_.Identity} | Where {$_.LastSuccessSync -gt '2/15/2012'} | Sort-Object -Property DeviceType,Identity | Select-Object @{name="EmailAddress";expression={$_.Identity.ToString().Split("\")[0]}},DeviceType,LastSuccessSync | Export-Csv -Path:"C:\MobileDevices.csv"

This code snippet was slightly modified from the one documented by Nick Smith on his following blog post: http://knicksmith.blogspot.com.au/2007/03/dst-and-mobile-devices.html

For Exchange 2010, you can't get much better then the PowerShell script Get-ActiveSyncReport.ps1 created by Paul A. Ponzeka and Paul Cunningham.  This script will generate you a CSV file and email you a formatted email with CSS styles created by Paul Cunningham which looks similar to the following screenshot:


To obtain a copy of the script, latest versions and additional information please refer to the following website:

http://port25guy.com/2013/03/25/how-to-get-a-report-of-active-sync-devices-in-exchange-2010exchange-2013/

It is important to note, that I will not be maintaining an updated copy of this script so please refer to the authors official website.  Encase something happens to this page in the future, to ensure this script remains available I have posted a copy of the code below.

### BEGINNING OF SCRIPT #####
#
# Get-ActiveSyncDeviceReport
# Author: Paul Ponzeka
# Website: port25guy.com
# email ponzekap2 at gmail dot com
#
######
param(
    [Parameter(Mandatory = $true)]
    [string] $SMTPServer = “”,
    [Parameter(Mandatory = $true)]
    [string] $SMTPFrom = “”,
    [Parameter(Mandatory = $true)]
    [string] $SMTPTo = “”,
    [Parameter(Mandatory = $true)]
    [string] $exportpath = “”
    )
 $SMTPServer = "ExchangeFQDN.domain.local"
$SMTPFrom = "
mrscript@domain.local"
$SMTPTo = "
mradministrator@domain.local"
$exportpath = "c:\"
#######
#
# HTML Formatting Section
# Thanks to Paul Cunningham at
http://exchangeserverpro.com/
#
#######
#
#
#
######
$style = “
$messageSubject = “ActiveSync Device Report” $message = New-Object System.Net.Mail.MailMessage $smtpfrom, $smtpto
$message.Subject = $messageSubject
$message.IsBodyHTML = $true
####  Get Mailbox $EASDevices = “”
$AllEASDevices = @()
$EASDevices = “”| select ‘User’,'PrimarySMTPAddress’,'DeviceType’,'DeviceModel’,'DeviceOS’, ‘LastSyncAttemptTime’,'LastSuccessSync’
$EasMailboxes = Get-Mailbox -ResultSize unlimited
foreach ($EASUser in $EasMailboxes) {
$EASDevices.user = $EASUser.displayname
$EASDevices.PrimarySMTPAddress = $EASUser.PrimarySMTPAddress.tostring()
    foreach ($EASUserDevices in Get-ActiveSyncDevice -Mailbox $EasUser.alias) {
    $EASDeviceStatistics = $EASUserDevices | Get-ActiveSyncDeviceStatistics
    $EASDevices.devicetype = $EASUserDevices.devicetype
    $EASDevices.devicemodel = $EASUserDevices.devicemodel
    $EASDevices.deviceos = $EASUserDevices.deviceos
    $EASDevices.lastsyncattempttime = $EASDeviceStatistics.lastsyncattempttime
    $EASDevices.lastsuccesssync = $EASDeviceStatistics.lastsuccesssync
    $AllEASDevices += $EASDevices | select user,primarysmtpaddress,devicetype,devicemodel,deviceos,lastsyncattempttime,lastsuccesssync
    }
    }
$AllEASDevices = $AllEASDevices | sort user
$AllEASDevices
$AllEASDevices | Export-Csv $exportpath\ActiveSyncReport.csv
######
#
# Send Email Report
#
########
$message.Body = $AllEasDevices | ConvertTo-Html -Head $style $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($message)
##END OF SCRIPT 



Important

 Make sure you fill out this section of the script:

$SMTPServer = "ExchangeFQDN.domain.local"
$SMTPFrom = "mrscript@domain.local"
$SMTPTo = "mradministrator@domain.local"
$exportpath = "c:\"
 

No comments:

Post a Comment