Decommissioning Windows Devices in Intune: Retire, Wipe, Cleanup
Decide between Retire and Wipe for a Windows device in Intune, then remove the Autopilot identity and hybrid AD object in order so re-enrolment does not fail.

In this lesson
Quick answer
A safe Windows decommission removes corporate access and data without losing the identifiers needed for audit or reuse. Confirm ownership first, choose Retire or Wipe deliberately, verify the result, and only then remove stale Intune, Entra ID and Autopilot records.
Table of Contents
Table of contents
Before you begin
- Basic familiarity with the Intune admin centre and device enrollment concepts
- Comfortable running Microsoft Graph PowerShell SDK commands
- Understanding of Entra ID device objects and hybrid Azure AD join
Track this tutorial
Choose your current status and tick each safety check as you complete it. Sign in to sync progress between devices.
Current status
Tutorial stages
- Step 1: Inventory and confirm device identity
- Step 2: Confirm data preservation
- Step 3: Raise and approve the change
- Step 4: Execute the correct removal action
- Step 5: Remove the Windows Autopilot device identity
- Step 6: Clean up hybrid AD remnants, and leave an Autopilot device's Entra ID object alone
0 of 6 stages complete
Before you apply the change
Confirm these production-safety controls during the tutorial.
Answer first: Choose Retire for supported selective corporate-data removal and Wipe for a factory reset, then verify each asynchronous action before cleaning up records in Microsoft’s order: delete the device from Intune, then deregister it from Windows AutopilotThe KBY LexiconWindows AutopilotWindows Autopilot registers device hardware identity to a tenant so new or reset Windows devices self-configure via Entra ID join and Intune policy during first boot. , then, for hybrid-joined devices, delete the on-premises AD computer object. If the device is registered with Windows Autopilot, don’t delete its Entra ID device object by hand: Microsoft advises against it unless a specific scenario requires it, because deleting it can cause enrolment failures. Device ownership, platform, and wipe options change the exact outcome, so confirm the current Microsoft action table and serial number before any destructive request.
Related KBY guidance: verify BitLocker recovery-key escrow before decommissioning.
#Operational requirement
Hardware refreshes and leaver offboarding generate a recurring, unglamorous task: taking a Windows device out of active management without leaving orphaned objects behind. This is usually one of the first real production assignments handed to a new endpoint engineer — “decommission these fourteen laptops from the finance floor refresh” or “process this leaver’s device by Friday”. It looks trivial. It is not.
Get the sequencing wrong and you produce one of three production incidents. First: you issue a full Wipe against the wrong serial number and destroy a working device’s local data with no way to recover it, because Wipe is irreversible by design. Second: a device leaves the organisation for good (recycled, sold or returned to the vendor) but its Windows Autopilot device identity is never deregistered, so it stays registered to your tenant and still goes through your Autopilot deployment when its next owner sets it up. Third: on a hybrid-joined estate, you clean up Intune but leave the on-prem AD computer object in place, so Entra Connect keeps resyncing a stale device record that a security audit will flag months later as an unaccounted-for endpoint.
This runbook walks a junior administrator through the correct decommission sequence: inventory and confirm, obtain change approval, execute the correct removal action (Retire versus Wipe), delete the device from Intune, deregister it from Windows Autopilot, clean up any hybrid AD remnants, and produce verifiable evidence that the device is retired from every system of record. Follow it step by step; do not skip the confirmation steps because the ticket seems routine.
#Prerequisites and required permissions
- An Entra ID account assigned the Intune Administrator role, or a custom Intune RBAC role granting the Managed devices/Delete, Remote tasks/Wipe and Remote tasks/Retire permissions, plus Managed devices/Read.
- Entra ID Cloud Device Administrator role, or equivalent, to remove device objects.
- Microsoft Graph PowerShell SDK installed on your admin workstation:
Install-Module Microsoft.Graph -Scope CurrentUser- Graph delegated scopes:
DeviceManagementManagedDevices.PrivilegedOperations.All,DeviceManagementManagedDevices.ReadWrite.All,Device.ReadWrite.All, andDeviceManagementServiceConfig.ReadWrite.Allfor Autopilot identity deletion. - An approved change record in your service management tool — bulk device wipe actions should never proceed on a verbal request alone.
- Confirmation that user data preservation, such as OneDrive Known Folder Move, has already completed, or an explicit written sign-off that no data preservation is required, for any device going through Wipe rather than Retire.
- Read access to your asset register so serial numbers can be cross-checked before any destructive action is issued.
#Step 1: Inventory and confirm device identity
Before touching anything, pull the exact managed device record and confirm you have the right hardware. Serial numbers and device names get transposed in spreadsheets constantly — this is the single most common cause of the “wrong device wiped” incident, and it is entirely preventable with one extra query.
1Connect-MgGraph -Scopes "DeviceManagementManagedDevices.PrivilegedOperations.All","DeviceManagementManagedDevices.ReadWrite.All","Device.ReadWrite.All","DeviceManagementServiceConfig.ReadWrite.All"
2
3Get-MgDeviceManagementManagedDevice -Filter "deviceName eq 'FIN-LT-0231'" | Select-Object Id, DeviceName, SerialNumber, UserPrincipalName, ManagedDeviceOwnerType, EnrolledDateTime, LastSyncDateTime, ComplianceStateExpected result: a single device record returned with a serial number matching your asset register. Evidence to capture: export this record into the change ticket before proceeding. Checkpoint: if ManagedDeviceOwnerType shows personal, stop. BYOD devices go through a Retire, never a full Wipe, and require a separate consent conversation with the user.
#Step 2: Confirm data preservation
For corporate-owned devices going to full Wipe, verify OneDrive sync health for the assigned user, or obtain explicit written confirmation from the requesting manager that no data preservation is needed. For lost or stolen devices, record that the data cannot be preserved and that the owner has accepted this. For BYOD devices, which go through Retire only, confirm the user has been told that corporate data and the management profile will be removed. Record the confirmation reference number in the ticket. This step exists because Wipe with keepUserData set to false is destructive, and Microsoft does not offer a recovery path from the managed-device side once the command has processed.
#Step 3: Raise and approve the change
Log a standard change with the device list, the action per device (Retire or Wipe), and a rollback plan attached. For batches larger than five devices, route the request through your change advisory board or equivalent lightweight approval. This is not because the technical risk is high; it is because the blast radius of a scripting mistake against the wrong device group is large enough to justify a second pair of eyes on the filter logic before execution. Pilot the sequence on a single device before running a batch.
#Step 4: Execute the correct removal action
Retire and Wipe are not interchangeable. Use the decision table below before issuing either command, and check the exact effect for the device’s platform and join type in Microsoft’s Intune remote actions documentation.

| Scenario | Action | Effect |
|---|---|---|
| Leaver, corporate device returns for reissue | Wipe (keepUserData:false) | Factory reset that removes local data. Whether enrolment data is kept depends on the keepEnrollmentData setting (see below) |
| BYOD, user leaving the programme | Retire | Removes corporate data and management profile; personal data is left |
| Corporate Microsoft Entra joined device you intend to Retire | Retire (only if the documented effect is what you want) | Different from BYOD: Microsoft documents that Retire removes the device’s Entra ID record (unless it is registered in Autopilot) and, with BitLocker, removes key protectors. Back up first (see below) |
| Device replaced under warranty, returned to vendor | Wipe | Ensures no residual corporate data leaves the estate |
| Device stolen or lost | Wipe | Microsoft lists Wipe for devices that need to be securely erased if lost or stolen. Don’t Retire instead: on a Microsoft Entra joined device protected by BitLocker, Retire removes the key protectors and suspends BitLocker on the OS volume |
Before you Retire a Microsoft Entra joined device, back up its BitLocker recovery key and local administrator account credentials. Microsoft lists both as critical data that may be lost in the process, and says a Retire removes the device’s Entra ID record unless the device is registered in Autopilot.
For Wipe, keepEnrollmentData and keepUserData control what survives. With keepEnrollmentData set to false, the enrolment state and associated management data are not retained, so the device will need to be enrolled again; with keepUserData set to false, user data is not kept. Confirm the exact behaviour for your platform in Microsoft’s documentation before choosing values.
First run the read-only checks and confirmation, then issue only one of the two actions below. Never run both against the same device.
1# Use the serial number confirmed in Step 1 (replace with the value from your asset register)
2$serial = 'PF3XK912'
3$found = @(Get-MgDeviceManagementManagedDevice -Filter "serialNumber eq '$serial'")
4if ($found.Count -ne 1) { throw "Expected exactly one managed device for serial $serial, found $($found.Count). Stop." }
5$deviceId = $found[0].Id # must equal the Id recorded in Step 1
6Write-Host "Target: $($found[0].DeviceName) / $($found[0].SerialNumber) / $deviceId"
7if ((Read-Host 'Type YES to proceed') -ne 'YES') { throw 'Cancelled by operator.' }Option A: Wipe (run this block only if the decision is Wipe)
1Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/$deviceId/wipe" -ContentType 'application/json' -Body (@{ keepEnrollmentData = $false; keepUserData = $false } | ConvertTo-Json) -StatusCodeVariable status
2$statusOption B: Retire (run this block only if the decision is Retire)
1Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/$deviceId/retire" -StatusCodeVariable status
2$statusExpected result: HTTPThe KBY LexiconHTTPHTTP is a stateless application-level protocol for request and response messages. Safe validation requires a bounded target and both protocol and application evidence.
204 No Content on success, captured in $status through -StatusCodeVariable. Evidence to capture: the response status, timestamp and device ID, pasted into the change ticket. Checkpoint: the action only processes when the device next checks in. Check the action state in Intune, and if the device is offline, note this in the ticket and set a follow-up reminder rather than assuming completion. Do not delete the device record or the Autopilot identity until the Intune action state shows the wipe or retire as complete; deleting earlier can leave data on a device that never processed the action.
#Step 5: Remove the Windows Autopilot device identity
First, delete the device from Intune. Microsoft’s order is fixed: a device has to be deleted from Intune before it can be deregistered from Windows Autopilot. Confirm first that the wipe or retire action state is complete. In the Intune admin centre, go to Devices, then Windows, select the device, note its serial number, and select Delete. Only then remove the Autopilot identity below.
Microsoft says to deregister a device whenever it permanently leaves the organisation, for example at the end of its life or when it leaves for repair. If the device is only being reissued internally, keep the registration and skip the deletion below, but unassign any user assigned to its Autopilot record. Microsoft’s deregistration steps also unassign any assigned user before the Autopilot record is deleted, as the script does.
1$serial = 'PF3XK912' # must match the serial number recorded in Step 1
2# Precondition: the managed device must already be gone from Intune
3if (@(Get-MgDeviceManagementManagedDevice -Filter "serialNumber eq '$serial'").Count -ne 0) { throw 'Device still exists in Intune. Delete it first. Stop.' }
4$autopilotDevice = @(Get-MgDeviceManagementWindowsAutopilotDeviceIdentity -Filter "contains(serialNumber,'$serial')" | Where-Object { $_.SerialNumber -eq $serial })
5if ($autopilotDevice.Count -ne 1) { throw "Expected exactly one Autopilot identity for $serial, found $($autopilotDevice.Count). Stop." }
6# Microsoft's order: unassign any assigned user, then delete the Autopilot record
7if ($autopilotDevice[0].UserPrincipalName) { Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/deviceManagement/windowsAutopilotDeviceIdentities/$($autopilotDevice[0].Id)/unassignUserFromDevice" }
8Remove-MgDeviceManagementWindowsAutopilotDeviceIdentity -WindowsAutopilotDeviceIdentityId $autopilotDevice[0].IdExpected result: the serial number no longer appears under Devices, Enrollment, Windows, Windows Autopilot, Devices in the Intune admin centre. Deregistration can take some time: select Sync, then Refresh every few minutes until the device is gone. Evidence: a before-and-after screenshot of the Autopilot device list. Checkpoint: once deregistered, the device is no longer associated with your tenant. If it is ever reused in your organisation, it must be registered again, by the reseller or by uploading its hardware hash.
#Step 6: Clean up hybrid AD remnants, and leave an Autopilot device’s Entra ID object alone
If the device is registered with Windows Autopilot, don’t delete its Entra ID device object by hand. Microsoft’s Autopilot guidance is that, for Microsoft Entra joined devices, no further steps are needed after deregistering the device from Windows Autopilot through Intune, and that manual deletion from Entra ID should be avoided unless a specific scenario requires it: the Autopilot deployment process relies on that object, and deleting it can cause enrolment failures. Microsoft notes the object can remain in Entra ID after deregistration.
For a device that isn’t registered with Autopilot, Microsoft’s Wipe guidance is different: after the action, you might also want to remove its record from Entra ID. It points to its guidance on managing stale devices in Microsoft Entra IDThe KBY LexiconMicrosoft Entra IDA concise technical definition of Microsoft Entra ID: what it is, how it fits identity architecture, and where engineers must validate before change. for how to do that. If the action was a Retire and the device is Microsoft Entra joined, Microsoft’s Retire guidance says the Retire itself removes that record, which is why Step 4 has you back up the BitLocker recovery key and local administrator credentials before retiring it.
If the device is Microsoft Entra hybrid joined, delete its computer object from on-premises Active Directory so that it isn’t resynced to Entra ID. Before you do, export any BitLocker recovery key for the device that is stored in Active Directory and that you might still need. Microsoft says that recovery information is stored in a child object of the computer object itself, and that old recovery keys aren’t removed automatically from AD DS unless the computer object is deleted. Fetch and verify the object first, then preview the deletion with -WhatIf:
1$comp = Get-ADComputer -Identity "FIN-LT-0231" -Properties DistinguishedName, Created
2$comp | Format-List Name, DistinguishedName, Created # confirm this is the device from Step 1
3
4# Review child objects (such as BitLocker recovery information) before deleting
5Get-ADObject -SearchBase $comp.DistinguishedName -SearchScope OneLevel -Filter *
6
7# If there are no child objects:
8Remove-ADComputer -Identity $comp -WhatIf
9# If the preview is correct, run without -WhatIf and answer the prompt.Remove-ADComputer deletes leaf objects only. If child objects exist, export the recovery keys you need first, then use Remove-ADObject, which has the -Recursive parameter, and preview it with -WhatIf before running it for real:
1Remove-ADObject -Identity $comp.DistinguishedName -Recursive -WhatIf
2# If the preview is correct, run without -WhatIf and answer the prompt.Finally, unassign the Microsoft 365 licence from the associated user if this decommission is tied to a leaver, so the seat is reclaimed on the next billing cycle rather than left consumed indefinitely. Log this action separately, as licence reconciliation is often audited independently of device cleanup.

#Verification
- Intune admin centre: device no longer listed under Devices, All devices.
- Autopilot device list: serial number absent.
- Entra ID: for an Autopilot device, the object may still be listed; Microsoft notes it can remain after deregistration. Don’t delete it by hand (Step 6). For a hybrid-joined device, it shouldn’t be resynced once the on-prem computer object is gone.
- Hybrid AD, where applicable: computer object absent from the relevant organisational unit.
- Licence report: seat reassigned or returned to the available pool.
- Change ticket: closed with all screenshots and command output attached, referencing the original change record.
Cross-check the Intune audit logs (Tenant administration, Audit logs) for the retire or wipe action, and the Entra audit log for any device deletion events, to confirm the actions were performed under your account and not duplicated by another administrator working the same batch. For recurring monthly refresh cycles, build a small dashboard query that lists devices marked for decommission against devices still appearing in Intune after seven days, so stalled offline devices surface automatically rather than being forgotten.
#Failure Modes
| Symptom | Likely cause | Fix |
|---|---|---|
| A device that has left the organisation still goes through your Autopilot deployment | Autopilot device identity not deregistered in Step 5 | Confirm the device is deleted from Intune, then deregister the identity (Step 5) |
| Wipe command accepted but device never actually resets | Device offline beyond the check-in window, action queued indefinitely | Confirm last check-in date; the action only fires on next contact, escalate for a manual power-on if urgent |
| Stale hybrid device keeps reappearing in Entra ID | Hybrid AD computer object not removed, so Entra Connect resyncs it | Export any BitLocker recovery key stored under the on-prem AD computer object that you might still need, then delete the object (Step 6). For an Autopilot device, don’t delete the Entra ID object by hand; Microsoft advises against it |
| Licence not reclaimed after wipe | Licence assignment is tied to the user object, not the device; wipe does not touch licensing | Explicitly unassign the licence from the user account |
| Wrong device wiped | Serial number transposition in the source spreadsheet | No data recovery is possible from the device; escalate immediately, restore user data from backup if one exists, document as an incident |
#Rollback
Treat a submitted Retire action as asynchronous but not safely reversible. Confirm the device action state in Intune; do not promise cancellation. If Retire has processed, restore management only through the approved enrolment path and reapply the device baseline. If the device has not checked in, escalate to the Intune owner before issuing any competing action.
Wipe actions cannot be rolled back once the device has processed the command. That is the entire point of Wipe. There is no vendor-supported reversal. A Wipe sent with keepEnrollmentData set to false does not retain enrolment data, so the device must be enrolled again; a Wipe with keepUserData set to false removes user data, which can only come back from OneDrive or a backup. Your rollback plan for a mistaken Wipe is: re-enrol the device through Autopilot or manual enrolment, reassign the user’s configuration profiles and app assignments from your baseline group, and restore any user data from the last known OneDrive or backup snapshot. Document the incident regardless of whether data was recoverable, and note the timestamp of the original mistaken command for the post-incident review.
If you deleted the wrong Autopilot identity, re-register the device using the hardware hash captured from Get-WindowsAutoPilotInfo, upload it via the Intune admin centre or partner portal, then reassign the correct deployment profile before returning the device to the field.
#Operational Summary
The deliverable for this task is a fully decommissioned device (deleted from Intune, deregistered from Windows Autopilot and, where hybrid-joined, removed from on-prem AD, with an Autopilot device’s Entra ID object left in place rather than deleted by hand) and a closed change ticket carrying command output, timestamps and before-and-after screenshots as evidence. Practise the full sequence on a single test device in a lab tenant before running it against a production batch: enrol a lab machine or virtual machine and register it for Autopilot, run all six steps, and confirm Intune, Autopilot and, where applicable, on-prem AD show the device as gone. That one successful dry run, captured in your own notes, is what tells your manager you are ready to run this against a real hardware refresh without supervision.
Treat the Retire-versus-Wipe decision as a data-protection decision, not a technical one. The moment you issue a Wipe, the outcome is final, so the discipline in this runbook is entirely about verifying identity and intent before the irreversible step, not about the mechanics of the API call itself. A newly hired engineer who can run this sequence cleanly, with evidence, on the first attempt has demonstrated exactly the kind of careful, verifiable operational discipline that endpoint management teams depend on.
#Learning Objectives
By the end of this runbook a junior administrator should be able to distinguish Retire from Wipe in operational terms, not just definitional ones, and select the correct action from device ownership type, physical state (returned, lost, stolen) and data-preservation status before any command is issued.
The administrator should be able to trace a single device through all four systems of record — Intune managed device, Windows Autopilot device identity, Entra ID device object, and hybrid on-prem AD computer object where applicable — and produce evidence of each one’s state (removed from Intune, Autopilot and on-prem AD, with an Autopilot device’s Entra ID object left in place rather than deleted by hand) instead of assuming success from a single console view.
A further objective is building the habit of a read-only confirmation query before every destructive call: retrieving the managed device record by serial number and cross-checking it against the asset register or ticket, so that the query itself becomes the rollback checkpoint rather than an afterthought.
Finally, the administrator should be able to explain, without notes, why a mistaken Wipe has no vendor-supported reversal while a submitted Retire cannot be reliably cancelled, and recovery means re-enrolling the device.
- Distinguish Retire, Wipe and selective wipe scenarios by device ownership and state
- Sequence Intune deletion, Autopilot deregistration and hybrid AD cleanup in Microsoft’s order, so no system resurrects a stale record
- Capture verifiable evidence (query output, timestamps, screenshots) at each stage rather than relying on console memory
- Articulate the rollback boundary between correctable and irreversible actions before issuing a command
#Practice Exercise
Use a real or virtual machine enrolled in a lab tenant, and register its hardware hash for Windows Autopilot, following the same dry-run principle recommended in the Operational Summary. Give it a device name that clearly marks it as non-production, for example LAB-TEST-0099, so it cannot be confused with a real asset during the exercise.
Run the Step 1 confirmation query against this test device and record the ManagedDeviceOwnerType, LastSyncDateTime and ComplianceState values before taking any action. This is your validation baseline — without it you cannot later prove the subsequent action changed the device's state as expected.
Issue a Retire against the test device and capture the response code and timestamp. Then attempt the Step 1 confirmation query again immediately afterwards; because Retire only processes on next check-in, the record should still be present, which is itself a useful validation that you understand the asynchronous nature of the action rather than a failure.
Delete the test device from Intune, then deregister its Autopilot identity, capturing before-and-after evidence exactly as described in Step 5. Because it’s an Autopilot device, leave its Entra ID device object in place, as Step 6 explains. Then attempt to reverse the exercise: re-register the same serial number as a fresh Autopilot identity and confirm a new deployment profile can be assigned, demonstrating the recovery path documented in the Rollback section without needing a real incident to practise it.
Close the exercise by writing a one-paragraph note describing what evidence you would have been missing if you had skipped the baseline query in the first step, and submit this alongside your command output as proof of readiness before touching a production batch.
Evidence trail
Sources and verification
Primary documentation and external technical references used in this article.
About this page
Credited to
Dates
Published
Corrections
- : Steps 4 and 6 gained the same note about what a Retire does to an Entra-joined device, and the hybrid Remove-ADComputer step now says to back up any BitLocker recovery information held in Active Directory first. That step is marked untested. Details
- : The earlier correction told readers never to delete any device's Entra ID object by hand. That advice is now limited to devices registered in Windows Autopilot, which is what Microsoft's guidance covers. Details
- : The guide told readers to delete the device's Entra ID object by hand, to deregister it from Autopilot without first deleting it from Intune, and to Retire a lost or stolen device. It now deletes the device from Intune first, names Wipe for lost or stolen devices, and no longer deletes the Entra ID object by hand. Details
Read-only scripts
- Windows devices with no BitLocker recovery key in Entra IDMicrosoft Entra ID, Windows
- Intune devices that haven't synced in N daysMicrosoft Intune
- Mailboxes forwarding to external addressesExchange Online
- BitLocker status of every volume on this PCWindows
Upcoming deadlines
- Intune moves to macOS 15 and laterQ4 2026
- SAP SuccessFactors provisioning: move from basic auth to workload identityNovember 2026
- Intune November release: JIT registration reminder at APNs renewal and automatic JIT for eligible tenantsNovember 2026
Explore KBY
The KBY Brief
A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.
SubscribeRelated articles
Endpoint and Device Management
Tracing an Endpoint and Device Management Problem with Microsoft Intune
Learn how Microsoft Intune delivers policy to devices, how to prove it with evidence, and how to run and reverse a safe bounded lab exercise.
Enterprise IT Management
Part 1: Windows Autopilot Prerequisites in Intune: Licences, Automatic Enrolment and Branding
Get the tenant ready for Windows Autopilot: licences, automatic Intune enrolment for a pilot group, Entra join permissions, branding, and the choice between classic Autopilot and device preparation.
Security & Operations
Microsoft Defender for Endpoint Device Stuck Onboarding or Inactive
A layered method for diagnosing Windows devices that show Inactive or never appear in Microsoft Defender for Endpoint.
Discover more
Graduate Learning
Ops Playbook
- PlaybookRoute Windows Autopilot Profiles With Group Tags and Dynamic Device Groups
- PlaybookIntune Endpoint Analytics Devices Missing Startup Performance Scores
- PlaybookIntune Remediation Script Shows Without Issues but Never Runs
- PlaybookEntra ID AADSTS7000222: Rotating Expired App Client Secrets Safely
Lexicon Definitions
Learn More About KBY
About KBY
Learn about our mission, how our content is produced, and how we handle corrections.
Why Trust KBY
How KBY content is produced, what is checked automatically, and how errors are corrected.
The KBY Brief
A short email about twice a week with new runbooks, configuration traps and fixes from KBY Technologies.
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Build practical engineering skills.
Receive new lessons, learning paths, practical exercises and early-career guidance.
Comments
Add a thoughtful note on Decommissioning Windows Devices in Intune: Retire, Wipe, Cleanup. Comments are checked for spam and held for moderation before appearing.