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.
Connect-MgGraph (Microsoft.Graph.Authentication)Get-MgDeviceManagementManagedDevice (Microsoft.Graph.DeviceManagement)managedDevice resource type (Intune): lastSyncDateTimeGet-Date (Microsoft.PowerShell.Utility)Where-Object (Microsoft.PowerShell.Core)Sort-Object (Microsoft.PowerShell.Utility)Select-Object (Microsoft.PowerShell.Utility)