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.

Microsoft Graph PowerShell
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

AuthorRole
Priyanshu UpadhyaySolution Architect, Microsoft 365 and Azure
Disclaimer. These samples are provided as is, without warranty of any kind. Read and test every script in a non-production tenant before you run it, and run reports before any command that changes or deletes data.