
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
- Copy and paste the following script into Notepad, Visual Studio Code or your favourite text editor.
$credentials = Get-Credential -Credential admin@contoso.onmicrosoft.com
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
- Replace admin@contoso.onmicrosoft.com with your Office 365 administrator email and C:\temp\MobileDevices.csv with the location that you want the CSV saved to.
- Save the script with the file extension .ps1

- Open Windows PowerShell by going to Start, and typing PowerShell

- Drag and drop the script onto the PowerShell window. Press enter to run it and enter your credentials.

- Wait for the script to complete, then find your exported CSV at the location you specified earlier. Eg. C:\temp\MobileDevices.csv



