Delete mailbox in Exchange Online – Soft delete vs Hard delete

In this article you will learn how to delete mailbox in Exchange Online using PowerShell. You will learn the difference between soft delete and hard delete mailbox, how to check soft deleted mailbox in Exchange Online, how to restore a mailbox, and how to hard delete a mailbox in Exchange Online.

How to delete mailbox in Exchange Online

Soft delete vs Hard delete mailbox

When you delete a mailbox in Exchange Online, it is retained in Soft Deleted Mailbox state for 30 days. Administrators have an option to restore the mailbox within this period. This state is called soft delete state.

If an administrator doesn’t restore the mailbox within 30 days, it is deleted permanently (provided litigation hold is not applied). Once the mailbox is deleted permanently, it can not be recovered. This state is called hard delete state.

Connect to Exchange Online and MSOnline PowerShell modules

To be able to run below commands, you need to connect to Exchange Online and MSOnline PowerShell modules. Open Windows PowerShell and run below commands one by one:

PowerShell
Connect-ExchangeOnline
Connect-MSolService
Soft delete mailbox in Exchange Online using PowerShell

To soft delete mailbox in Exchange Online, we will use Remove-Mailbox PowerShell command as shown below:

PowerShell
Remove-Mailbox -Identity "damoSMB" -Confirm:$false

The above command will soft delete mailbox “damoSMB”. To verify the mailbox in soft delete state, run below PowerShell command:

PowerShell
Get-Mailbox -Identity "damoSMB" -SoftDeletedMailbox

To verify all mailboxes in soft deleted sate, run below PowerShell command:

PowerShell
Get-Mailbox -SoftDeletedMailbox

Important: When you soft delete a mailbox in Exchange Online, the associated user account also gets soft deleted.

To verify the soft deleted user account for this mailbox, you need to run below command:

PowerShell
Get-MsolUser -ReturnDeletedUsers

The above command will display the soft deleted user account as shown below:

verify the soft deleted user account
Recover deleted mailbox in Exchange Online using PowerShell

To recover soft deleted mailbox in Exchange Online, run below PowerShell command:

PowerShell
Undo-SoftDeletedMailbox -SoftDeletedObject "damoSMB"

Important: The above command will recover soft deleted mailbox “damoSMB” and its associated user account.

Hard delete mailbox in Exchange Online

To hard delete a mailbox in Exchange Online, you need to first delete the user account associated with that mailbox. If you will try to delete an active user mailbox without deleting the associated account, you will get an error that says “This mailbox cannot be permanently deleted since there is a user associated with this mailbox in Azure Active Directory“.

To delete a user account associated with the mailbox, run below PowerShell command:

PowerShell
Remove-MsolUser -UserPrincipalName "[email protected]" -Force

To delete the user account permanently, run below PowerShell command:

PowerShell
Remove-MsolUser -UserPrincipalName "[email protected]" -RemoveFromRecycleBin -Force

To hard delete a mailbox, run below PowerShell command:

PowerShell
Remove-Mailbox -Identity "damoSMB" -PermanentlyDelete -Force

Conclusion

In this article you learnt how to delete mailbox in Exchange Online. You might like our other articles on Manage user mailbox using PowerShell, Manage shared mailbox using PowerShell.

If you found this article helpful and informative, please share it within your community and do not forget to share your feedback in the comments below.

Join us on YouTube for the latest videos on the Cloud technology and join our Newsletter for the early access of the articles and updates.

Happy Learning!!