Export a list of mobile devices connected to Office 365

Export Mobile Users

If you’re Administering an Office 365 organisation, you may want to find out which users are accessing Office 365 email via their mobile device. This can be helpful for a number reasons, including security of data or planning user training.

Here’s a script that will export a CSV of the mobile devices in your organisation, as well as the users accounts that are running on them.

How to export a list of Office 365 Mobile Devices

  1. Copy and paste the following script into Notepad, Visual Studio Code or your favourite text editor.
    $credentials = Get-Credential -Credential [email protected]
    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
  1. Replace [email protected] with your Office 365 administrator email and C:\temp\MobileDevices.csv with the location that you want the CSV saved to.
  2. Save the script with the file extension .ps1Save As PowerShell Script File
  3. Open Windows PowerShell by going to Start, and typing PowerShellOpen PowerShell
  4. Drag and drop the script onto the PowerShell window. Press enter to run it and enter your credentials.Export Mobile Users
  5. Wait for the script to complete, then find your exported CSV at the location you specified earlier. Eg. C:\temp\MobileDevices.csvCSV Of Mobile Devices In Office 365

Was this article helpful?

Related Articles