Clean Up Stale Devices in Microsoft Entra ID and Intune
Every reimaged laptop, replaced phone and departed user leaves a device object behind. Stale devices make it hard for the help desk to tell which device is live and slow down Microsoft Entra Connect device writeback (What is a stale device (opens in a new tab)). This guide hides stale records in Intune, then disables and later deletes stale devices in Microsoft Entra ID, without losing BitLocker keys or breaking Autopilot.
Before you start
- Roles: Cloud Device Administrator or Intune Administrator to update devices in Microsoft Entra ID (Cleanup account (opens in a new tab)); Intune Administrator (or a custom role) for Intune cleanup rules (Cleanup rule prerequisites (opens in a new tab)).
- License: Intune cleanup rules only act on devices enrolled in Intune, which is licensed per user or device (see the Intune column of Require a compliant device on License requirements).
- BitLocker: BitLocker keys stored in Microsoft Entra ID live on the device object, and deleting the device deletes them with no way to recover (BitLocker keys (opens in a new tab), Delete devices (opens in a new tab)).
- Tools: Microsoft Graph PowerShell (
Get-MgDevice,Update-MgDevice,Remove-MgDevice) (Clean up stale devices (opens in a new tab)).
Step by step
- Pick a timeframe. Microsoft Entra ID updates the activity timestamp (
ApproximateLastSignInDateTime) only when it changes by more than 14 days (plus or minus 5), so don’t treat anything younger than 21 days as stale (Activity timestamp (opens in a new tab), Timeframe (opens in a new tab)). Microsoft’s examples use 90 days to disable and 120 to delete. - Hide stale records in Intune. In the Intune admin center, go to Devices > Organize devices > Device cleanup rules > Create, pick a platform, and set Remove devices that haven’t checked in for this many days (30 to 270). Use Preview affected devices first (Create a cleanup rule (opens in a new tab)). Cleanup rules only hide records; they don’t wipe or retire, and they don’t remove the device from Microsoft Entra ID (Device cleanup rules (opens in a new tab)).
- Retire managed devices first. If Intune or another MDM manages a device, retire it there before disabling or deleting it in Microsoft Entra ID (MDM-controlled devices (opens in a new tab)).
- Export the list. Run
Get-MgDevice -Alland filter onApproximateLastSignInDateTimeolder than your cutoff, exporting AccountEnabled, DeviceId, OperatingSystem, DisplayName, TrustType and the timestamp to CSV (Get the list of devices (opens in a new tab)). Compare it with your Autopilot list fromGet-MgDeviceManagementWindowsAutopilotDeviceIdentity(Autopilot devices (opens in a new tab)). - Disable, don’t delete. Set
accountEnabledto false withUpdate-MgDeviceand wait out a grace period. A deletion can’t be undone if you hit a false positive (Disable devices (opens in a new tab), Set devices to disabled (opens in a new tab)). - Handle hybrid joined devices on-premises. For Windows 10 or newer hybrid joined devices, disable or delete them in on-premises AD and let Microsoft Entra Connect sync the change (Hybrid joined devices (opens in a new tab)).
- Delete after the grace period. Back up any BitLocker keys you need, then remove devices that are still disabled and past your delete cutoff with
Remove-MgDevice, which doesn’t ask for confirmation (Delete devices (opens in a new tab)).
Gotchas
- Don’t delete system-managed devices such as Autopilot; once deleted, they can’t be reprovisioned (System-managed devices (opens in a new tab)). Deleting a device tied to an Autopilot object can make self-deploying and pre-provisioning deployments fail (Autopilot devices (opens in a new tab)).
- Deleting a Windows 10 or newer hybrid joined device only in Microsoft Entra ID brings it back from on-premises as a new object in Pending state, and the device has to re-register (Hybrid joined devices (opens in a new tab)).
- Deleting a device object doesn’t remove the registration on the device itself; it only stops the device being used as an identity, for example for Conditional Access (Joined devices (opens in a new tab)).
- Some active devices have a blank timestamp, so a blank value isn’t proof a device is stale (Warning (opens in a new tab)).
- If both a platform-specific and an All platforms cleanup rule exist in Intune, the one with fewer days applies (Create a cleanup rule (opens in a new tab)).
Check it worked
- The Activity column on All devices in the Microsoft Entra admin center shows no enabled devices older than your cutoff (Get the activity timestamp (opens in a new tab)).
- Intune audit logs show Device set to be hidden from admin by Device Cleanup Rule entries (Cleanup rules logging (opens in a new tab)).
- No help desk reports from users who can’t sign in on a device you disabled; a disabled device can’t authenticate to Microsoft Entra ID (What happens when I disable a device (opens in a new tab)).
Roll back
During the grace period, re-enable a device by setting accountEnabled back to true. A device hidden by an Intune cleanup rule reappears if it checks in before its device certificate expires (Device cleanup rules (opens in a new tab)). Deleted devices can’t be recovered (Delete devices (opens in a new tab)).
Related on EntraReady: Troubleshooting device join, Windows Autopilot troubleshooting, Windows LAPS with Intune, and Require compliant devices.
Sources (Microsoft Learn): Manage stale devices in Microsoft Entra ID (opens in a new tab), Intune device cleanup rules (opens in a new tab).
← All GuidesIs this still accurate?
Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.