Delete Exchange mailbox without deleting User account

Default behavior of Exchange is when you delete a mailbox the useraccount will also be deleted.
The procedure to keep the user account and only delete the Mailbox will be  :

Disable the mailbox and then delete the mailbox to retain the user account. The disabled mailbox will be stored in the database for up to 14 days.

First run this Query to check the mailboxes and their mailboxGuid’s.

Get-Mailbox -Database “Mailbox Database 0213232677” -IgnoreDefaultScope | Get-MailboxStatistics | ft DisplayName,MailboxGUID,TotalitemSize,LastLogonTime
Get-Mailbox -ResultSize Unlimited | Where-Object {$true} -PipelineVariable mb | Get-MailboxStatistics | Select-Object DisplayName, LastLogonTime, @{N=’UserPrincipalName’; E={$mb.UserPrincipalName}}   Get-Mailbox -ResultSize Unlimited | select -expand userprincipalname | Get-MailboxStatistics ft DisplayName,MailboxGUID,TotalitemSize,LastLogonTime
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | ft DisplayName,MailboxGUID,TotalitemSize,LastLogonTime

Step 1 : Disable Mailbox

Open Exchange Management Shell

Disable mailbox powershell command :

Disable-Mailbox [email protected]

Disable-Mailbox “John Matthew”
Disable-Mailbox <GUID>

To check if this worked use the following Powershell command :

$dbs = Get-MailboxDatabase $dbs | foreach {Get-MailboxStatistics -Database $_.DistinguishedName} | where {$_.DisplayName -eq ” <<user display name>> “} | Format-List DisconnectReason,DisconnectDate
If the command returns no results :
Get-mailboxDatabase
Get-MailboxStatistics -Database “Mailbox Database 0213232677” | foreach {Update-StoreMailboxState -Database $_.Database -Identity $_.MailboxGuid -Confirm:$false}
 

In the Exchange Management Shell, replace <UserIdentity> with the name or user principal name of the user (for example, [email protected]), and run this command to verify that the RecipientType property value is User, not UserMailbox.

Get-User -Identity <UserIdentity>

Step 2 : Delete mailbox

The disabled mailbox will be stored in the database for up to 14 days.

Get-MailboxDatabase

Get-MailboxStatistics -Database “Mailbox Database 0213232677” | where {$_.disconnectdate -ne $null}
or
Get-MailboxStatistics -Database “Mailbox Database 0213232677” | where {$_.disconnectreason -ne $null} | select displayname,MailboxGUID

To delete the disabled mailbox we need to  the GUID of the mailbox :

Get-MailboxStatistics -Database “Mailbox Database 0213232677” | where {$_.disconnectdate -ne $null} | select displayname,MailboxGUID,TotalItemSize,

To delete the disabled mailbox :

Remove-Mailbox -Database “Mailbox Database 0213232677” -StoreMailboxIdentity 4e168d0f-a98c-4012-bf75-90c93810d16c

The disabled mailbox is deleted.

Official Microsoft documentation :

https://docs.microsoft.com/en-us/exchange/recipients/disconnected-mailboxes/disable-or-delete-mailboxes?view=exchserver-2019

https://docs.microsoft.com/en-us/powershell/module/exchange/get-mailboxstatistics?view=exchange-ps

Leave a Reply

Your email address will not be published.