Get Mobile Device Statistics In Exchange Online Using Powershell

Recently I was checking out my Azure tenant to see which mobile devices are currently in play. This reason for this was to see if there were any stale devices that can be deleted or if there were devices of a certain type that I wanted to filter. For this I would use the Get-MobileDevice and Get-MobileDeviceStatistics cmdlets to, well… Get Mobile Device Statistics in Powershell.


One of the prerequisites you’ll need to in order to make this happen is to install the Exchange Online module. Luckily it’s not too difficult if you follow the linked article. Another requirement is the account you’re using must have the Exchange Administrator role to be able to query Exchange Online.

So in short, here is what you’ll need.

  • Exchange Online Management Module
  • Exchange Administrator or Global Administrator Role

Exchange Admin Role in Azure

Get Mobile Device Statistics Using Powershell

Alright now that we know what we need, let’s look at how to extract that information from Exchange Online. As mentioned we will be using the Get-MobileDevice cmdlet along with the Get-MobileDeviceStatistics to get the different properties. Get-MobileDevice has a mailbox parameter so we can filter devices that are associated with a mailbox, assuming you only wanted a single user’s device. Let’s look at what that looks like in the shell.

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName [email protected]

Get-MobileDevice -Mailbox pcontreras | select @{Name = 'Identity' ; Expression = {$_.Identity -replace "\\.+"}}, `
DeviceId, IsManaged, IsCompliant, DeviceOS, DeviceType, FriendlyName, `
DeviceUserAgent, FirstSyncTime, DeviceAccessState, DeviceAccessStateReason, ClientType -First 1

Identity                : Paul Contreras
DeviceId                : D1151F256364422E827C79AF3D3B2230
IsManaged               : False
IsCompliant             : False
DeviceOS                : iOS 13.7
DeviceType              : Outlook
FriendlyName            :
DeviceUserAgent         : Outlook-iOS/2.0
FirstSyncTime           : 9/12/2020 2:43:42 AM
DeviceAccessState       : Allowed
DeviceAccessStateReason : ExternallyManaged
ClientType              : Outlook

Get-MobileDevice cmdlet output

Get Mobile Device Statistics show similar results, however, I do like the fact that it has a LastSuccessSync and LastSyncAttemptTime to see exactly how long devices have been stale. If you’re really good with with regex, you can parse the text in the Identity property to give you just the name. My regex game is really weak so if you know how to do that, please post it in the comments so other viewers can use it as well.

Powershell Script To Get Device and Statistics

Since I like to use these 2 cmdlets interchangeably, I thought it would be helpful to provide a script so you can call the Get-MobileDeviceStatistics using the GUID from Get-MobileDevice output.

#Get all mobile devices in the org
$MobileDeviceList = Get-MobileDevice

#Alternatively, Get all mobile devices from a single user
$MobileDeviceList = Get-MobileDevice -Mailbox [email protected]

foreach ($Device in $MobileDeviceList) {
    $Stats = Get-MobileDeviceStatistics -Identity $Device.Guid.toString()
        Identity              = $Device.Identity -replace "\\.+"
        DeviceType            = $Device.DeviceType
        DeviceOS              = $Device.DeviceOS
        LastSuccessSync       = $Stats.LastSuccessSync
        LastSyncAttemptTime   = $Stats.LastSyncAttemptTime
        LastPolicyUpdateTime  = $Stats.LastPolicyUpdateTime
        LastPingHeartbeat     = $Stats.LastPingHeartbeat
        ClientType            = $Stats.ClientType

Identity             : Paul Contreras
DeviceType           : Outlook
DeviceOS             : iOS 13.7
LastSuccessSync      : 9/12/2020 2:43:43 AM
LastSyncAttemptTime  : 9/12/2020 2:43:43 AM
LastPolicyUpdateTime : 9/12/2020 2:43:43 AM
LastPingHeartbeat    :
ClientType           : Outlook

Identity             : Paul Contreras
DeviceType           : iPhone
DeviceOS             : iOS 14.1 18A8395
LastSuccessSync      : 11/12/2020 2:40:02 AM
LastSyncAttemptTime  : 11/12/2020 2:40:02 AM
LastPolicyUpdateTime : 11/11/2020 6:32:40 PM
LastPingHeartbeat    : 600
ClientType           : EAS

Get Mobile Device Statistics Function


Alright folk, hopefully this article was useful enough to provide you the information needed to get mobile device statistics using Powershell. Furthermore, I hope it was enough to determine which of those devices are stale and no longer in use. This is an excellent strategy for when you want to do some spring cleaning.

If you like to see more cloud content, be sure to check out our Office 365 Cloud Category for more useful tips and tricks. Finally, be sure to stop by our Youtube Page for those visual learners.


Hi, my name is Paul and I am a Sysadmin who enjoys working on various technologies from Microsoft, VMWare, Cisco and many others. Join me as I document my trials and tribulations of the daily grind of System Administration.