Friday, June 6, 2014

Decomissioning Obsoltete SMTP Domains


Hi folks,

I have recently helped my client to decommission one of their obsolete SMTP domains.

For the sake of this article let's call SMTP domain ancientdomain.com.

My special thanks to the author of this article which helped me to do the trickiest bit e.g. removing aliases from bunch of mailboxes.

My client had quite a few mailboxes which were assigned aliases from which I had to scrap this out. It's worthy to mention that these mailboxes were stored in particular databases so I used -Database parameter when creating variables for the mailboxes. If you have a different scenario, you may want to use a different filter. For example: -ResultSize Unlimited (as in the original article) if you want to scrap it out of all mailboxes in your organization.

By this code I have removed aliases from mailboxes stored in the particular database:

$Mailboxes = Get-Mailbox -Database DB03
$Mailboxes | foreach{
    for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
    {
        $address = $_.EmailAddresses[$i]
        if ($address.IsPrimaryAddress -eq $false -and $address.SmtpAddress -like "*ancientdomain.com" )
        {
            Write-host($address.AddressString.ToString() | out-file d:\scripts\addressesRemoved.txt -append)
            $_.EmailAddresses.RemoveAt($i)
            $i--
        }
    }
    Set-Mailbox -Identity $_.Identity -EmailAddresses $_.EmailAddresses}


Another nice feature of this code is out-file d:\scripts\addressesRemoved.txt -append which outputs list of removed aliases thus giving us reporting and control over which domains were removed from the mailboxes.

Ok, the first and the trickiest bit is done. Now we need to prevent organization receiving emails to the ancientdomain.com. To do this we need to remove accepted domain and ensure that accepted domain removal is synced to Edge Transport servers (as in my environment, yours may differ especially if you have a different messaging hygiene solution, still you will need to remove it from there).

The first bit is straightforward and needs really no comments:

Remove-AcceptedDomain ancientdomain.com



In case of edge servers I didn't want to wait till next Edge Sync and forced it. As a lazy person I scripted it into the following code so that it runs against all Edge Transport servers in the organization:

$Edge = Get-ExchangeServer | Where-Object {$_.ServerRole -eq "Edge"}
$Edge | foreach {Start-EdgeSynchronization -Server HUBSERVER -TargetServer $_.Name}

And that's the whole magic.

No comments:

Post a Comment