Finding a complete list of mobile devices in Office 365 that have not synced in X days can be a bit of a task through the online portal. This script will connect to your Office 365 environment and export all those mobiles that have not syncronised in the last 14 days.

The Cmdlet in this script are for tenants that have been upgraded to Wave 15. If you are still running Wave 14, then replace Get-MobileDeviceStatistics with Get-ActiveSyncDeviceStatistics

 

 

PowerShell
Edit|Remove
<# 
 
    .PURPOSE 
        Script will output a full list of mobile devices that have not 
        synced in 14 days 
 
    . EXAMPLES 
        PS> InactiveMobiles.ps1 
 
    .OUTPUT 
        UserPrincipalname 
        DeviceModel 
        LastSuccessSync 
 
    .NOTES 
        For Wave 14 Customers change the Get-MobileDeviceStatistics to Get-ActiveSyncDeviceStatistics 
 
    .AUTHOR 
        Dan Rose 
 
#> 
 
function ConnectTo-ExchangeOnline  
{    
    <# 
        .SYNOPSIS 
            Connects to Exchange Online with tenant credentials 
 
        .INPUT 
            Tenant Username/Password 
 
        .RETURN 
            None 
 
    #> 
 
    # Get Credentials  
    $Office365Credentials = Get-Credential 
     
    # Create remote Powershell session  
    $Script:Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $Office365credentials -Authentication Basic –AllowRedirection          
  
    # Import the session  
    Import-PSSession $Session -AllowClobber | Out-Null  
}  
 
ConnectTo-ExchangeOnline 
 
# Gather Mailboxes 
$users = Get-Mailbox -ResultSize Unlimited  
 
foreach ($user in $users) { 
 
    # Get mobiles that have not synced for the last x days 
    $mobiles = Get-MobileDeviceStatistics -Mailbox $user.identity | 
        where {$_.LastSuccessSync -lt (Get-Date).AddDays(-14)} | 
        select DeviceModel,LastSuccessSync 
 
    
    foreach ($mobile in $mobiles) { 
     
        $ObjProperties = New-Object PSObject 
 
        Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "UserPrincipalName" -Value $user.userprincipalname 
        Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "DeviceModel" -Value $mobile.DeviceModel 
        Add-Member -InputObject $ObjProperties -MemberType NoteProperty -Name "LastSuccessSync" -Value $mobile.LastSuccessSync 
 
        $objProperties 
     
        # Output to file 
        $MobileString = "$($user.userprincipalname),$($mobile.DeviceModel),$($mobile.LastSuccessSync)" 
        Out-File -FilePath "c:\inactivemobiles.csv" -InputObject $MobileString  -Encoding UTF8 -append 
 
    } 
} 
 
Remove-PSSession $Script:Session