Reporting all ActiveSync devices and their Users in Exchange 2010

Exchange-2010-Logo-748516Recently I needed to report on the ActiveSync devices that were attached to our Exchange 2010 organisation, and which users they were accessing, and then export them to a CSV file.

This is the script:

$ActiveSyncDevices = @()

ForEach ($Mailbox in Get-Mailbox –Server MBX01) {
Get-ActiveSyncDeviceStatistics -Mailbox $Mailbox.Identity –ErrorAction SilentlyContinue | Select DeviceFriendlyName, Devicetype, DeviceUserAgent | ForEach-Object { $_ | Add-Member –MemberType NoteProperty -Name "MailboxIdentity" -value $Mailbox
$ActiveSyncDevices += $_ }

$ActiveSyncDevices | Export-csv c:\Path\To\File.csv

Walking through the script it gets all the mailboxes from the server MBX01, gets an object containing the ActiveSync device name, type and user agent. It then adds a property to that object called “MailboxIdentity” and adds it to that object. That object is then added to an array of objects called ActiveSyncDevices, which is then exported to CSV.