Library

Guides Quick Fixes Scripts Find a Guide

Tools

Error Decoder Assessment Baselines Free Tools Service status What's Changed

More

AI Certifications For MSPs Recommended Gear Field Kit FAQ About Contact Get Assessment

Clean Up Stale Devices in Microsoft Entra ID and Intune

EntraReady Guides · Practical Microsoft 365 & Entra ID
Last reviewed:
Last verified against Microsoft Learn:

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

Step by step

  1. 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.
  2. 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)).
  3. 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)).
  4. Export the list. Run Get-MgDevice -All and filter on ApproximateLastSignInDateTime older 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 from Get-MgDeviceManagementWindowsAutopilotDeviceIdentity (Autopilot devices (opens in a new tab)).
  5. Disable, don’t delete. Set accountEnabled to false with Update-MgDevice and 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)).
  6. 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)).
  7. 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

Check it worked

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 Guides

Is this still accurate?

Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.

Reports go to the EntraReady inbox. Please don’t include passwords or tenant secrets.