Exporting Exchange 2010 ActiveSync statistics for iOS Devices


Update 22/10/2012: For the most up to date version of this script, see my post Exporting iOS 6 and earlier device information”

When exporting ActiveSync statistics from your Exchange Server 2010 environment, you’ve got a number of options, including using the Export-ActiveSyncLogs cmdlet to parse IIS log files and produce a number of CSV reports to help understand the way your ActiveSync devices are being used, the use of Device troubleshooting logs to retrieve client-side logs on a user-by-user basis to help diagnose issues, and use of the Get-ActiveSyncDeviceStatistics cmdlet to interrogate the information stored by Exchange and Active Directory about each ActiveSync device partnership.

The final option is what provides the foundation for this script, however when just exporting information on it’s own the built in cmdlet doesn’t interpret the information encoded in the User Agent string that helps understand what versions of iOS are in use across your business. Therefore as well as exporting the data from Exchange, this script maps the information stored in Exchange to iOS versions.


.\Export-MessageTrackingLogsForRecipient.ps1 -OutputCSVFile C:\output.csv

Example Output:


Script (downloadable below)

# Generates a CSV file containing ActiveSync Device Statistics with iOS Specific Information.
# Filename to save the output CSV file as
# .\Export-MessageTrackingLogsForRecipient.ps1 -OutputCSVFile C:\output.csv
[parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Output CSV File Name")][string]$OutputCSVFile
# The following is a Hash Table containing information used to
# map the Apple Device User Agent to it's corresponding iOS version
# Retrieve mailboxes of users who have a connected ActiveSync Device
$CASMailboxes = Get-CASMailbox -Filter {hasactivesyncdevicepartnership -eq $true -and -not displayname -like "CAS_{*"} -ResultSize Unlimited;
[array]$Mailboxes = $CASMailboxes | Get-Mailbox;
# Create an array to store the output
# Perform a set of actions against each mailbox retrieved
foreach ($Mailbox in $Mailboxes)
# Retrieve the ActiveSync Device Statistics for the associated user mailbox
[array]$ActiveSyncDeviceStatistics = Get-ActiveSyncDeviceStatistics -Mailbox $Mailbox;
# Use the information retrieved above to store information one by one about each ActiveSync Device
foreach ($Device in $ActiveSyncDeviceStatistics)
# Where possible use the information stored in the Device User Agent to understand the iOS device version in use
$iOSVersion = "N/A";
if ($Device.DeviceUserAgent -like "*/*") {
$rawiOSVersion = ($Device.DeviceUserAgent).Substring(($Device.DeviceUserAgent).IndexOf("/")+1);
if ($iOSVersions[$rawiOSVersion])
$iOSVersion = $iOSVersions[$rawiOSVersion];
# Create a new object to store this ActiveSync device information in our CSV file
$OutputItem = New-Object Object;
# Add information to the object
$OutputItem | Add-Member NoteProperty Username $Mailbox.SamAccountName;
$OutputItem | Add-Member NoteProperty "Display Name" $Mailbox.DisplayName;
$OutputItem | Add-Member NoteProperty "Device Type" $Device.DeviceType;
$OutputItem | Add-Member NoteProperty "Device Model" $Device.DeviceModel;
$OutputItem | Add-Member NoteProperty "iOS Version" $iOSVersion;
$OutputItem | Add-Member NoteProperty "Device ID" $Device.DeviceID
$OutputItem | Add-Member NoteProperty "Status" $Device.Status
$OutputItem | Add-Member NoteProperty "ActiveSync Policy" $Device.DevicePolicyApplied
$OutputItem | Add-Member NoteProperty "ActiveSync Policy Status" $Device.DevicePolicyApplicationStatus
$OutputItem | Add-Member NoteProperty "Last Sync" $Device.LastSuccessSync
$OutputItem | Add-Member NoteProperty "Last Sync Attempt" $Device.LastSyncAttemptTime
$OutputItem | Add-Member NoteProperty "Last Policy Update" $Device.LastPolicyUpdateTime
$OutputItem | Add-Member NoteProperty "First Sync" $Device.FirstSyncTime
# Add the object to our array of output objects
$Output += $OutputItem;
# Print the output object to the screen in a table format with a subset of details for ease of reading
$Output | Format-Table Username,"Device Type","Device ID","Last Sync"
# Export the full set of data to the specified CSV file
$Output | Export-CSV -Path $OutputCSVFile -NoTypeInformation

Version 1.0, 5th December 2011

Download ExportActiveSyncDeviceStatistics.zip

15 thoughts on “Exporting Exchange 2010 ActiveSync statistics for iOS Devices

  1. Pingback: How to Export Exchange 2010 ActiveSync statistics for IOS Devices. - Nagle Ki Duniya

  2. Pingback: Home – ExchangeServerInfo » Exchange – ActiveSync Device Reporting

  3. Hi Steve,

    Thank you for the script. I’m a complete novice to powershell and would love to export IOS devices to migrate users to an MDM solutions. When running your script in Exchange 2007 management shell on a Windows 2008 server, i receive the following script error:

    [PS] C:\TEMP>.\iphonestat.ps1 -OutputCSVFile .\iphonestat.csv Unable to find type parameter(Position=1,Mandatory=$true,ValueFromPipeline=$fa
    lse,HelpMessage=”Output CSV File Name”)]: make sure that the assembly containin
    g this type is loaded.
    At C:\TEMP\Iphonestat.ps1:10 char:104 +
    e=”Output CSV File Name”)][ <<<< string]$OutputCSVFile

    How do i correct this error?

    Thanks again

  4. Cool script, where did you find the match-up values? I still get alot of N/A in my environment, even though the device is iPad/iPhone.. So I think we need more match-up values…

  5. Works well
    Of course the problem is keeping it up to date. I found two entries for iOS 5.1:

  6. Steve, thank you very much for script. It works great…question for you? would running this powershell script cause sync issues for users(outlook on the iphone for example) while the script was running or right after it ran? It was really weird today but right around the time i ran the script people received prompts to re-enter their info on their iphones for Microsoft outlook. Thoughts?

  7. Pingback: How to Export Exchange 2010 ActiveSync statistics for IOS Devices. « msexchangeanywhere

Comments are closed.