Decommissioning Exchange Server

I had recently been tasked with removing one exchange server from an on-prem three-node cluster. These are the steps that I had to take to remove the server. As with any decommissioning process, make sure to take a full backup and arrange for downtime 🙂

Before runs command bring is exchange snap in for on Exchange PowerShell by running below

Exchange 2007:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin;

Exchange 2010:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010;

Exchange 2013:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;

Before decom server mailboxes need to move to another DB.

Before you move the mailboxes, run the Set-ADServerSettings cmdlet, including the -ViewEntireForest parameter. This will let you view the objects in the entire forest.

Set-ADServerSettings -ViewEntireForest $true

  • Run the Get-MailboxDatabase cmdlet, including the -Status parameter, to check which mailbox databases are present and whether they are mounted.

Get-MailboxDatabase -Status | Sort Name | Format-Table Name, Server, Mounted

  • Run Get-Mailbox to find all mailboxes in the database that you are going to delete.

Get-Mailbox -Database “DB01” -ResultSize Unlimited

Move all mailboxes from one database to another with the New-MoveRequest cmdlet.

Get-Mailbox -Database “DB01” -ResultSize Unlimited | New-MoveRequest -TargetDatabase “DB02”

Move Archive mailbox

Find archive mailboxes in the database.

Get-Mailbox -ResultSize Unlimited | Where {$_.ArchiveDatabase -like “DB01”}

Move archive mailboxes to another database.

Get-Mailbox -ResultSize Unlimited | Where {$_.ArchiveDatabase -like “DB01”} | New-MoveRequest -ArchiveTargetDatabase “DB02”

Move Public folder mailbox

Find public folder mailboxes in the database.

Get-Mailbox -Database “DB01” -PublicFolder

Move public folder mailboxes to another database.

Get-Mailbox -Database “DB01” -PublicFolder | New-MoveRequest -TargetDatabase “DB02”

Move Arbitration mailbox

Find arbitration mailboxes in the database.

Get-Mailbox -Database “DB01” -Arbitration

Move arbitration mailbox to another database.

Get-Mailbox -Database “DB01” -Arbitration | New-MoveRequest -TargetDatabase “DB02”

Move Audit Log mailbox

Find audit log mailboxes in the database.

Get-Mailbox -Database “DB01” -AuditLog

Move audit log mailboxes to another database.

Get-Mailbox -Database “DB01” -AuditLog | New-MoveRequest -TargetDatabase “DB02”

Disable Monitoring mailbox

Find monitoring mailboxes associated with the mailbox database.

Get-Mailbox -Database “DB01” -Monitoring | Format-Table Name, DisplayName, Database, Servername

Disable monitoring mailboxes.

Get-Mailbox -Database “DB01” -Monitoring | Disable-Mailbox -Confirm:$false

Please note that the above listed steps need to be done for each DB on the server that is going to remove in order to remove all the mailbox DBs from the server.

Verify mailboxes move

Verify that all the mailboxes are moved. After that, remove  completed move requests. If you don’t, you will get the error this mailbox database is associated with one or more move requests. If you want to remove all move requests, run the third command.

Get-MoveRequestStatistics -MoveRequestQueue “DB02”

To remove only selected DB moves,

Get-MoveRequest -SourceDatabase “DB02” -MoveStatus Completed -ResultSize Unlimited | Remove-MoveRequest -Confirm:$false

If you want to remove all the move request run,

Get-MoveRequest -MoveStatus Completed -ResultSize Unlimited | Remove-MoveRequest -Confirm:$false

Get-MoveRequest -ResultSize Unlimited | Remove-MoveRequest -Confirm:$false

Reboot the server

Make sure to check send connectors and Firewall to see any dependencies before remove completely.

Set the Exchange to maintenance mode

Set-ServerComponentState <ServerName> -Component ServerWideOffline -State Inactive -Requester Maintenance

Validate

Get-ServerComponentState <ServerName> | Format-Table Component,State -Autosize

After that you will need to go to ECP and delete the DBs. After that on the exchange server you will be able to uninstall from add/remove in control panel.

Some Useful Documents:

https://practical365.com/decommissioning-exchange-on-premises-servers-and-consolidating-email-smtp-relays/
https://www.alitajran.com/list-mailboxes-in-database/
https://www.alitajran.com/get-exchange-mailbox-database-mount-status-with-powershell/
https://www.alitajran.com/cannot-delete-mailbox-database-exchange/

Search and Delete an Email from office365.

Here is the steps to find and delete a specific mail from mailbox(s) from the office365 exchange.

1. Install PowerShell 7 using the following command:  winget install –id Microsoft.Powershell –source winget . Because complaince task need new PS.

2. PowerShell 7 will install side-by-side with your current version of Powershell. You will be able to find it using Search or in Start->All Programs. Start it

3. Install the Exchange Online Management Module using the command : install-module exchangeonlinemanagement

4. Connect to Exchange Online using the command: connect-exchangeonline. You will be asked to authenticate using your credentials ( Make sure the account that using has proper permission)

5. Connect to Security and Compliance Online using the command:  Connect-IPPSSession. You will be asked to authenticate using your credentials

6. Create a new compliance search: New-ComplianceSearch -Name “Give it a title” -ExchangeLocation All -ContentMatchQuery ‘(Received>=10/22/2020 -AND Received<=10/25/2020) AND (Subject:”provide words/phrase to look for in the subject”) AND (From:sender email address)’

7. Start the search with the command: start-compliancesearch “use the title you gave it above”

8. Check on the status of the search with the commanD: get-compliancesearch “user the title you gave it”. You can also use the command – get-compliancesearch “user the title you gave it” | fl, for more details and find out if any emails were found. You will not see a list in the results, but just a number.

9. If there were emails and you want to delete them then use the command: New-ComplianceSearchAction -SearchName “provide the title from above” -Purge -PurgeType SoftDelete

10. Check on the status: Get-ComplianceSearchAction “the title from above and append _purge”

References: 

1. https://learn.microsoft.com/en-us/powershell/exchange/connect-to-scc-powershell?view=exchange-ps 

2. https://learn.microsoft.com/en-us/purview/ediscovery-search-for-and-delete-email-messages

3. https://adamtheautomator.com/office-365-delete-email/