Retrieve Active Sync Client Information

We are currently going through a migration from on-premise Microsoft Exchange servers to Microsoft Exchange Online (Microsoft 365). We needed to determine what ActiveSync clients were in use to be able to provide guidance to users of what to do. So I wrote a simple script that retrieves all the mailboxes (that are enabled) and then determines if any mobile devices have been registered with it, it then outputs the results into a CSV file for further analysis.

Its simple enough to run the script, you just run it from a machine with Microsoft Exchange management tools and requires sufficient access permissions to retrieve the list of user mailboxes and their attributes.

You can find the script below, customise the path where you want to write the CSV, in two places (sorry) it was a very quick knocked together script.

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

# ActiveSync Client Report - Per User Mailbox v0.2
# Written in a hurry, no error checking or fancy features, remove the filter on the get-mailbox to see all of the things. 

Write-Output ""
Write-Host "ActiveSync Client Report - Per User Mailbox" -ForegroundColor Green
Write-Output ""

$asyncusers = Get-Mailbox -ResultSize Unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox') -and (IsMailboxEnabled -eq $True)}

$DeviceCount = 0

# Write the top line of the CSV File
$NewRow = "Identity,ClientType,DeviceModel,DeviceOS,DeviceUserAgent,DeviceActiveSyncVersion,LastSuccessSync"
$NewRow | Add-Content -Path c:\asyncsuer.csv

# Loop through each mailbox and retrieve the device(s) if they exist, then write them to a file.
foreach ($asyncuser in $asyncusers) {
    $DeviceLines = Get-ActiveSyncDeviceStatistics -Mailbox $asyncuser.alias -WarningAction SilentlyContinue | Select-Object * 
    write-Host "$($asyncuser.alias) ($($DeviceLines.Count))" -ForegroundColor Yellow
    if ($DeviceLines.Count -gt 0) {
        foreach ($DeviceLine in $DeviceLines) {
            write-output "> $($DeviceLine.ClientType) - $($DeviceLine.DeviceModel) - $($DeviceLine.DeviceOS) - $($DeviceLine.DeviceUserAgent) - $($DeviceLine.DeviceActiveSyncVersion) - $($DeviceLine.LastSuccessSync)"
            $NewRow = "$($asyncuser.alias),$($DeviceLine.ClientType),$($DeviceLine.DeviceModel),$($DeviceLine.DeviceOS),$($DeviceLine.DeviceUserAgent),$($DeviceLine.DeviceActiveSyncVersion),$($DeviceLine.LastSuccessSync)"
            $NewRow | Add-Content -Path c:\asyncsuer.csv
        }
        $DeviceCount = 0
    }
    write-output ""
    $DeviceCount = 0
}

Leave a comment