Skip to main content
Microsoft Intune · PowerShell 7.6

Intune devices that haven't synced in N days

Which Intune-managed devices have not completed a successful sync with Intune in the last 30 days (or however many days you pass)?

Script

#Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.DeviceManagement
# Intune managed devices whose last successful sync is older than -Days. Read-only.
param(
    [int]$Days = 30
)

Connect-MgGraph -Scopes 'DeviceManagementManagedDevices.Read.All' -NoWelcome

$cutoff = (Get-Date).AddDays(-$Days)

Get-MgDeviceManagementManagedDevice -All -Property 'id', 'deviceName', 'userPrincipalName', 'operatingSystem', 'osVersion', 'complianceState', 'managementAgent', 'lastSyncDateTime' |
    Where-Object { $_.LastSyncDateTime -lt $cutoff } |
    Sort-Object LastSyncDateTime |
    Select-Object DeviceName, UserPrincipalName, OperatingSystem, OsVersion, ComplianceState, ManagementAgent, LastSyncDateTime

Checked automatically against Microsoft's published cmdlet reference. KBY hasn't run it in your tenant; run it in a test environment first.

Reading the output

  • Uses lastSyncDateTime, which the managedDevice resource defines as the last successful sync with Intune.
  • Run with -Days to change the threshold, for example -Days 14.

Sources

The Microsoft reference page for every cmdlet the script calls, plus the API and product pages behind each permission and caveat.

All scripts