How to delete mailboxes in Exchange Server 2007/2010/2013/2016/2019

How to delete mailboxes from Exchange Server

Before I get technical, a word of warning. Please, make sure you are removing the right mailboxes. Just in case, temporarily forget about using -Confirm:$false parameter.

Before you start deleting mailboxes, make sure you have sufficient permissions. To run the Remove-Mailbox cmdlet, you need to have the Mail Recipient Creation role assigned. By default, only members of Organization Management and Recipient Management role groups have sufficient privileges.

How to delete a single mailbox in Exchange Server

  1. Make sure you are removing the right mailboxes.
  2. Make sure you have sufficient permissions.
  3. Delete a single mailbox using cmdlet: Remove-Mailbox <Mailbox-you-want-to-delete>

Mind that using the cmdlet from above soft-deletes the mailbox of your choosing. Soft-deletion means that the mailbox is marked for purging and will be permanently deleted as soon as the mailbox deletion retention period passes. The default retention period is 30 days. To check the retention period in your organization, run the following cmdlet:

Get-MailboxDatabase | FL -Property PSComputerName,MailboxRetention

In Exchange Server 2019/2016 you can add the –Permanent parameter to skip the soft-deletion phase.

Mind that for a single mailbox deletion you can also use the ADUC or ADSIEdit.

How to delete multiple mailboxes in Exchange Server

  1. Make sure you are removing the right mailboxes.
  2. Make sure you have sufficient permissions.
  3. Delete multiple mailboxes using cmdlet within a pipeline. For example, if you want to delete members of a certain distribution group, use: Get-DistributionGroupMember <name of a distribution group> | remove-mailbox -whatif

Why use the -whatif switch? Just in case. Thanks to this attribute, you can see which mailboxes you will delete with the cmdlet. When you confirm you want to delete the chosen mailboxes, use the cmdlet without the -whatif switch.

You can also quickly delete inactive mailboxes using the following script:

Get-Mailbox -ResultSize Unlimited –RecipientTypeDetails UserMailbox,SharedMailbox | Where {(Get-MailboxStatistics $_.Identity).LastLogonTime -lt (Get-Date).AddDays(-90)} | Remove-Mailbox -whatif

The script above (after deleting the -whatif switch) removes all mailboxes which have been inactive for more than 90 days. Again, make sure you want to remove all of them – some users might not have logged in to their mailboxes because of a long-term leave.

How to permanently delete a disconnected mailbox in Exchange

If you delete an AD user, their mailbox becomes disconnected. This situation might happen when a user leaves the company, and their AD account is deleted. Disconnected mailboxes are purged automatically when the deleted mailbox retention period passes (30 days by default). When you deal with disconnected mailboxes, you can either reconnect them or delete them permanently. But first, you need a way to identify them.

The following cmdlet shows you the list of disconnected mailboxes in your on-prem Exchange Server:

Get-MailboxDatabase | Get-MailboxStatistics | Where { $_.DisconnectReason -ne $null } | ft DisplayName,MailboxGuid,DisconnectDate,DisconnectReason

If you want to permanently delete all disconnected mailboxes, pipeline the results from the previous cmdlet to the Remove-StoreMailbox cmdlet:

Get-MailboxDatabase | Get-MailboxStatistics | Where {$_.DisconnectReason -ne $null} | ForEach {Remove-StoreMailbox -Database $_.database -Identity $_.MailboxGuid -MailboxState Disabled}

How to solve problems with deleting mailboxes on Exchange Server

When your remove-mailbox cmdlet fails, you might get an error:

You do not have sufficient privileges to delete…, or this object is protected from accidental deletion.”

Now, if you have ensured that you have sufficient privileges, this error might be caused by the user protection. You can turn off the accidental deletion protection using the following cmdlet.

Set-ADObject <problematic-user> -ProtectedFromAccidentalDeletion:$false

Another way to turn off this feature is via Active Directory Users & Computers. First, right-click the problematic user and choose Properties:

ADUC properties-How to delete mailboxes from Exchange Server

Next, go to the Object tab and unmark Protect object from accidental deletion.

Protect from accidental deletion - how to delete mailboxes

If you still encounter some issues after unmarking the option, go to the Security tab and click Advanced:

Security - How to delete mailboxes from Exchange Server

In this window, click Restore defaults and apply the changes.

Security Advanced how to delete mailboxes

The next time you attempt to delete a user along with the mailbox, there should be no error.

Suggested Reading

Tools for Microsoft 365

Recommended articles

How to migrate from Exchange Server 2016/2019 to Microsoft 365

How to migrate from Exchange Server 2016/2019 to Microsoft 365

Migrating Exchange data to the cloud is not rocket science – explore your options and launch the migration stress-free. As you may already know, Exchange Server 2016 and 2019 have reached end of life and are no longer officially supported by Microsoft. If your organization still uses either of these platforms to manage email, contacts, calendars, and tasks, keep in mind that: Your environment may become vulnerable to newly discovered security threats – Microsoft will no longer provide security updates for Exchange 2016 and 2019 (unless you’ve enrolled in the Extended Security Update program, which ends in October 2026). Your emails may get blocked – Microsoft has started to throttle and block emails sent from unsupported Exchange Server versions to Exchange Online (as I covered in this article). That said, migrating to a supported platform is now the only viable long-term option for keeping your organization’s email environment secure, supported, and fully operational. If your organization wants or needs to keep things on‑premises (and continue using Microsoft’s solutions for that), upgrading to Exchange Server Subscription Edition (SE) is the only path forward. But given Microsoft’s clear preference for its cloud services – evident in the faster rollout of new features and the many security capabilities available exclusively in Microsoft 365 (Office 365) – now is a great time to leave your on‑prem environment behind and migrate to Exchange Online as part of Microsoft 365. While switching over to a new platform might seem like a rough ride, I’ll show you some easy ways to follow when migrating mailboxes from Exchange Server 2016/2019 to Microsoft 365. How to prepare for email migration to Microsoft 365 Before you start the migration process, you need to make sure your environment is ready for the move. For this purpose, you can use this guide in the Microsoft 365 admin center – it will help you connect your organization to Microsoft 365 and integrate your existing user accounts with Microsoft Entra ID. Microsoft also recommends completing the steps below: Set up an SPF record to determine valid email sources for your organization’s Microsoft 365 domain. Set up the Exchange Online Protection service as a means of protection against spam and malware. If you’re behind on updates, make sure to install the latest Cumulative Update (CU). And here is my quick, less obvious Microsoft 365 migration checklist: Verify if your software will work in Microsoft 365 (especially when it comes to server software). Microsoft 365 migration might be the time you learn that there is crucial legacy software that half the company uses and which is hard to replace. Encourage the whole company to clean up projects. It’s much easier to do this before the migration and start fresh. Gather as much information about your on‑premises environment as possible. For example, you might need to recreate access roles and permissions from scratch in the cloud or set up mail flow rules. Without prior research, it will be much more difficult. Verify if you need to migrate service accounts. There can be a lot of them on‑premises and in most cases, you won’t need them after the move. Review mailbox size limits in Exchange Online before migration to see which licenses you’ll need and whic
New-ComplianceSearch: how to use the newer version of Search-Mailbox

New-ComplianceSearch: how to use the newer version of Search-Mailbox

Microsoft retired the Search-Mailbox cmdlet – now what? Discover how to use New-ComplianceSearch, its key advantages and how to make the switch seamlessly.
How to start remote PowerShell session to Exchange or Microsoft 365

How to start remote PowerShell session to Exchange or Microsoft 365

One of many features of the PowerShell command line tool is its ability to connect with and manage the Exchange Server remotely. The procedure described below applies to the classic on-prem Exchange server and to the Microsoft 365/Exchange Online version.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

CodeTwo sp. z o.o. sp. k. is a controller of your personal data.
See our Privacy Policy to learn more.