Date created: Sunday, December 11, 2011 8:20:58 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM

List Domains and Primary Addresses

This will list the domains for which a mail server routes mail. Also it lists all mailboxes that have that domain set as their primary SMTP address;

$AcceptedDomains = Get-AcceptedDomain | select DomainName
foreach ($EachDomain in $AcceptedDomains)
{
  echo $EachDomain.DomainName.toString(); Get-Mailbox | where {$_.PrimarySMTPAddress -like ("*" + $EachDomain.DomainName)} | sort-object Name | fl Name, PrimarySMTPAddress
}

Example output:

xyzcorp.com


Name               : User 123
PrimarySmtpAddress : user123@xyzcorp.com

Name               : Info
PrimarySmtpAddress : info@xyzcorp.com


abcltd.org


Name               : helpdesk
PrimarySmtpAddress : helpdesk@abcltd.org

Name               : CEO Dave
PrimarySmtpAddress : dave@abcltd.org

Previous page: Export to PST
Next page: List Primary SMTP Addresses