Forum Discussion
Get a list of mobile devices syncing with my tenant
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
- liamf91Jan 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- solliergDec 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 $sessionThis script loops a second time on every user founded. Hope it helps !