Case : Uninstallation of an Exchange Server 2013 after Exchange Online Migration, non hybrid environment.
Mailbox cleaning
Get-User | Disable-Mailbox
Get-Mailbox -Arbitration | Disable-Mailbox -Arbitration -DisableLastArbitrationMailboxAllowed
Get-Mailbox -Monitoring | Disable-Mailbox
Removing restore mailbox
Get-Mailbox | Get-MailboxStatistics | Where {$_.DisconnectReason -eq “Disabled” } |foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled}
Get-Mailbox | Get-MailboxStatistics | where {$_.DisconnectReason -eq “SoftDeleted”} |foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState SoftDeleted}
Removing Offline Address book
Get-OfflineAddressBook | Remove-OfflineAddressBook
Verify nothing’s left
Get-Mailbox
Get-Mailbox -Arbitration
Get-Mailbox -Monitoring
Remove Database
Get-MailboxDatabase | Remove-MailboxDatabase
Remove partner application
Get-PartnerApplication| Remove-PartnerApplication
Run Exchange uninstallation
Setup /Mode:Uninstall /iacceptexchangeserverlicenseterms