Powershell Remove Non-Routable proxyaddresses for mailbox migration to Exchange Online

When doing a migration from onrem to Exchange Online / Office 365, the proxy addresses on the mail object must all be internet routable. If you have aliases like @domain.local, these need to be removed before the mailbox can be moved.

I used this powershell script to accomplish this in my environment:

 

<#
.Synopsis
Remove nonroutable smtp aliases in preparation for mailbox migration
.DESCRIPTION
Long description
.EXAMPLE
remove-nonRoutableSmtpAddresses -Searchbase "OU=OrgUnit,DC=Domain,DC=com" -smtpsuffix "nonroutable.domain" -Verbose
#>
function remove-nonRoutableSmtpAddresses
{
[CmdletBinding(SupportsShouldProcess)]
Param
(
# Search base of users to search for
[Parameter(Mandatory=$true,
Position=0)]
$Searchbase,

# SMTP suffix to find and remove
[Parameter(Mandatory=$true,
Position=1)]
$smtpsuffix
)


$smtpsuffix = ("*" + $smtpsuffix + "*")
$users = get-aduser -Filter {proxyaddresses -like $smtpsuffix} -Properties proxyaddresses -SearchBase $Searchbase
foreach ($u in $users){
Get-ADUser $u -Properties proxyaddresses `
| foreach {$pr = $_.proxyaddresses -like $smtpsuffix}
set-aduser $u -Remove @{proxyaddresses=$pr} -verbose
}
}

Powershell Get List of Domain Contollers

Simple is better. And this is by far the simplest way I have found to get a cleanly formatted list of domain controllers in a domain:

Encase the get-addomain cmdlet in parentheses and call the property replicadirectoryservers.

Example:

PS C:\DEV> (Get-ADDomain domain.local).ReplicaDirectoryServers
NY-DC01.domain.local
NY-DC02.domain.local
BOSTON-DC01.domain.local
BOSTON-DC02.domain.local