Powershell to export list of Exchange Server Mailbox email addresses

this powershell snippet will export all the SMTP email addresses used on a mail server, useful to document and check on them.

;
Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}
 ;

Or to get them all with each address on a new line (for easier importing etc…)

$a=get-mailbox

$objs=@() ; 
foreach ( $u in $a ) {
    foreach ( $ua in $u.emailaddresses ) {
        if ( $ua.prefixstring -ceq "smtp") { 
            $obj=New-Object psobject 
            add-member -inputobject $obj -membertype NoteProperty -name "Alias" -value $u.alias 
            add-member -inputobject $obj -membertype NoteProperty -name "primarysmtpaddress" -value $u.primarysmtpaddress  ; 
            add-member -inputobject $obj -membertype NoteProperty -name "email" -value $ua.smtpaddress
            $objs += $obj  
            }
       }
             
  }

$objs

About Jeff Turner

Technical director of Nano Tera Network Solutions.
This entry was posted in Hints and Tips and tagged , , . Bookmark the permalink.