Cleanup · 1 tool
Stale Intune devices not seen for 90 days
Summary
Finds managed devices that have not checked in for 90 days. Review the list, then retire or delete them so device counts, compliance reports and licence numbers are accurate.
Implementation
Choose your tool. Your choice is remembered on other samples.
Connect-MgGraph -Scopes DeviceManagementManagedDevices.ReadWrite.All -NoWelcome
$cutoff = (Get-Date).AddDays(-90).ToString("yyyy-MM-ddTHH:mm:ssZ")
$stale = Get-MgDeviceManagementManagedDevice -All -Filter "lastSyncDateTime le $cutoff"
$stale | Select-Object DeviceName, UserPrincipalName, OperatingSystem, LastSyncDateTime, ManagedDeviceOwnerType, SerialNumber |
Export-Csv .\stale-devices.csv -NoTypeInformation
# After review, delete (cannot be undone):
# $stale | ForEach-Object { Remove-MgDeviceManagementManagedDevice -ManagedDeviceId $_.Id }Prerequisites
- Graph scope DeviceManagementManagedDevices.Read.All (ReadWrite.All to delete)
Output
CSV of stale devices. The delete line is commented out on purpose.
Contributors
| Author | Role |
|---|---|
| Priyanshu Upadhyay | Solution Architect, Microsoft 365 and Azure |
InnovaticT