Get a list of mobile devices syncing with my tenant

Steel Contributor

Hi All

 

Hope everyone is well. Can someone perhaps assist me please?

 

I need to get list of all the mobiles devices that is currently syncing with my Office 365 tenant.

 

I found some scripts online but I am bit reluctant to use those.

 

Appreciate any advice...

4 Replies

You can try this script

 

$credential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $credential -Authentication Basic -AllowRedirection
Import-PSSession $Session

$mdevices = Get-MobileDevice -ResultSize Unlimited
$mdevices | Foreach-Object{
$mdevice = $_
$mstats = $mdevice | Get-MobileDeviceStatistics
New-Object -TypeName PSObject -Property @{
UserDisplayName = $mdevice.UserDisplayName
DeviceFriendlyName = $mdevice.FriendlyName
DeviceId = $mdevice.DeviceId
DeviceImei = $mdevice.DeviceImei
DeviceFirstSyncTime = $mdevice.FirstSyncTime
DeviceAdminDisplayName = $mdevice.AdminDisplayName
DeviceName = $mdevice.Name
DeviceLastSuccessSync = $mstats.LastSuccessSync
DevicePhoneNumber = $mstats.DevicePhoneNumber
Status = $mstats.Status
}
}|Export-csv -Path C:\result.csv -NoTypeInformation

 

If you don't want to use PowerShell, simply use the Exchange Online Admin Center? There is also an report in the O365 admin portal: https://portal.office.com/adminportal/home#/reportsUsage/EmailClients

@Manidurai Mohanamariappan4 years later :D - the script works near perfect - sadly looks like when it loops some may generate an error:

Get-MobileDeviceStatistics: Ex9E65A2|Microsoft.Exchange.Configuration.Tasks.ManagementObjectAmbiguousException|The operation couldn't be performed because 'xxxx\xxxxxxxxxxxx' matches multiple entries

@liamf91 

 

Hello,

I found this post that solves this "Multiple entries" issue. Here's a sample of the code :

 

    $credentials = Get-Credential -Credential email address removed for privacy reasons
    Write-Output "Getting the Exchange Online cmdlets"
 
    $session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
        -ConfigurationName Microsoft.Exchange -Credential $credentials `
        -Authentication Basic -AllowRedirection
    Import-PSSession $session
 
$csv = "C:\temp\MobileDevices.csv"
$results = @()
$mailboxUsers = get-mailbox -resultsize unlimited
$mobileDevice = @()
 
foreach($user in $mailboxUsers)
{
$UPN = $user.UserPrincipalName
$displayName = $user.DisplayName
 
$mobileDevices = Get-MobileDevice -Mailbox $UPN
       
      foreach($mobileDevice in $mobileDevices)
      {
          Write-Output "Getting info about a device for $displayName"
          $properties = @{
          Name = $user.name
          UPN = $UPN
          DisplayName = $displayName
          FriendlyName = $mobileDevice.FriendlyName
          ClientType = $mobileDevice.ClientType
          ClientVersion = $mobileDevice.ClientVersion
          DeviceId = $mobileDevice.DeviceId
          DeviceMobileOperator = $mobileDevice.DeviceMobileOperator
          DeviceModel = $mobileDevice.DeviceModel
          DeviceOS = $mobileDevice.DeviceOS
          DeviceTelephoneNumber = $mobileDevice.DeviceTelephoneNumber
          DeviceType = $mobileDevice.DeviceType
          FirstSyncTime = $mobileDevice.FirstSyncTime
          UserDisplayName = $mobileDevice.UserDisplayName
          }
          $results += New-Object psobject -Property $properties
      }
}
 
$results | Select-Object Name,UPN,FriendlyName,DisplayName,ClientType,ClientVersion,DeviceId,DeviceMobileOperator,DeviceModel,DeviceOS,DeviceTelephoneNumber,DeviceType,FirstSyncTime,UserDisplayName | Export-Csv -notypeinformation -Path $csv
 
Remove-PSSession $session

 

This script loops a second time on every user founded. Hope it helps !