Report proxy addresses not in Accepted Domains


Like as the waves make towards the pebbled shore, so do our proxy addresses hasten to multiply.

At least, that's how it seems.  As is the organizational ebb and flow, business objectives change, new business units are spun up, old projects are turned down, and you may need to add or remove proxy addresses in your Exchange environment to account for that.  Frequently, there are orphans in this process.

If you are contemplating a move to Office 365, you may want to take this time to identify proxy addresses stamped on your on-premises users that don't match your accepted domains.  The things you care about, in addition to achieving world peace and if a light beer can truly taste great and be less filling:

  • primary and secondary SMTP addresses that don't match accepted domains
  • primary and secondary SIP addresses that don't match accepted domains
  • user principal names that don't match accepted domains

It's actually easier than you think:

$Users = Get-Mailbox -ResultSize Unlimited
$AcceptedDomains = (Get-AcceptedDomain).DomainName
$SMTPregex = "((^(?i)smtp:\S*)(" + ($AcceptedDomains -join "|") + ")|(^(?i)x500:)|(^(?i)sip:\S*)(" + ($AcceptedDomains -join "|") + "))"
$UPNRegex = "(?i)(" + ($AcceptedDomains -join "`$|") + "`$)"
$Output = $Users | ForEach-Object {
 if (($_.EmailAddresses -notmatch $SMTPRegex) -or ($_.userprincipalname -notmatch $UPNRegex))
 {
 [pscustomobject]@{
 samAccountName = $_.samaccountname
 ProxyAddress = (($_.EmailAddresses -notmatch $SMTPRegex) -join ",")
 UserPrincipalName = ($_.UserPrincipalName)
 }
 }
}

There. All done.

You can then view the results of $Output or export it to a CSV:

$Output | Export-Csv output.csv -NoTypeInformation

 

Comments (0)

Skip to main content