Others

How to Automatically Delete Disabled Microsoft 365 Users

Elise WilliamsElise Williams Oct 28, 2026 869 views

Question details

The user wants to automate the permanent deletion of Microsoft 365 user accounts that have been disabled for a specified retention period.

How to Automatically Delete Disabled Microsoft 365 Users After a Set Period
Product
Microsoft 365
Device & OS
not provided
Scenario
Managing the Microsoft 365 user lifecycle and performing administrative clean-up for inactive accounts.
Observed behavior
The user needs a time-based automated deletion mechanism, which is not natively available as a toggle in the standard Microsoft 365 admin center interface.
Before you start

Ensure you have global administrator or user administrator permissions in your Microsoft 365 tenant. It is highly recommended to secure legal holds or back up critical mailbox and OneDrive data before executing permanent deletion scripts.

Solution 1Recommended

Use a PowerShell Automation Script

Since Microsoft 365 does not have a native UI setting for time-based deletion, PowerShell is the standard and approved method for automating this user account lifecycle task.

The Microsoft 365 Admin Center lacks a built-in time-based deletion tool for disabled users. To achieve this, IT administrators must rely on Microsoft Graph PowerShell to script the deletion based on the account's disabled status and last activity date.

Always test your scripts in a non-production environment or utilize the '-WhatIf' parameter to preview the results before enabling permanent deletion.

1
Connect to Microsoft 365 via PowerShell

Open Windows PowerShell as an Administrator and connect to your Microsoft 365 environment using the Connect-MgGraph command, ensuring you grant the required Directory.ReadWrite.All scopes.

2
Query Disabled Users

Run a query to filter users whose AccountEnabled property is set to False, and check their last modification or sign-in date to ensure they meet your defined retention period.

3
Execute the Remove Command

Pipe the filtered user objects to the Remove-MgUser cmdlet to delete the accounts. You can use Windows Task Scheduler or Azure Automation to run this script automatically on a periodic schedule.

Use a PowerShell Automation Script
Seek Scripting Guidance: For specific script writing assistance and best practices, post your query in the official Microsoft Q&A forums under the Windows Server or PowerShell categories.
Free Microsoft Office alternative

Need a Lightweight Office Suite for Your Team? Try WPS Office

While managing Microsoft 365 users requires complex PowerShell scripting, day-to-day document creation shouldn't be difficult. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office, perfect for teams looking to reduce licensing costs without sacrificing productivity.

Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Free to download and use with a familiar, easy-to-navigate tabbed interface.Lightweight installation that runs smoothly on both modern and older hardware.Built-in PDF editing, cloud collaboration, and comprehensive document management tools.
microsoft office alternative - wps office

Frequently Asked Questions

Can I auto-delete users directly from the Microsoft 365 Admin Center?

No, the standard Microsoft 365 Admin Center interface does not currently offer a built-in feature or setting to automatically delete disabled user accounts after a set time period.

What happens to user data when a Microsoft 365 account is deleted?

When a Microsoft 365 user account is deleted, their associated data (such as their Exchange mailbox and OneDrive files) is retained for a standard 30-day grace period. After 30 days, the data is permanently destroyed unless a specific retention hold was previously applied.

How can I prevent accidental deletion when automating with PowerShell?

Before running any automated PowerShell deletion script in production, implement detailed logging, use the '-WhatIf' parameter to safely preview which accounts will be affected, and configure safeguard checks to skip accounts with specific admin roles.

Where can I find examples of PowerShell scripts for Microsoft 365 automation?

You can find verified PowerShell script examples, module documentation, and community guidance in the official Microsoft Learn portal and Microsoft Q&A forums.