Forum Discussion
Navishkar Sadheo
Sep 20, 2018Iron Contributor
Get a list of mobile devices syncing with my tenant
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...
liamf91
Jan 03, 2023Copper Contributor
Manidurai Mohanamariappan4 years later 😄 - 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
sollierg
Dec 04, 2023Copper Contributor
Hello,
I found https://gcits.com/knowledge-base/export-a-list-of-mobile-devices-connected-to-office-365/ 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 !