none
How to list email addresses and aliases for each user? RRS feed

  • Question

  • How to list email addresses and aliases for each user?

     

    Hi All,

     

    I've been using the exchange power shell to to get a listing of all user’s primary smtp address along with each alias smtp addresses a user may have. An example of what i'm after is:

     

    Joe@domain.com Primary SMTP

    Joe1@domain.com alias 1

    Joe2@domain.com alias 2

     

    Jim@domain.com Primary SMTP

    Jim1@domain.com alias1

     

    and so on...

     

    I've tried several things found by searching but none do what I'm after.

     

    Any suggestions?

     

    Thanks in advance!!!

     

    Wednesday, February 17, 2010 3:08 PM

Answers

  • Hi,

    Is this you are looking for?

    get-mailbox | select -expand emailaddresses alias
    Regards from www.windowsadmin.in
    • Marked as answer by emma.yoyo Wednesday, February 24, 2010 1:22 AM
    • Edited by ManU PhiliP Monday, July 28, 2014 6:49 AM
    Thursday, February 18, 2010 4:21 AM
  • Hi,

    Here is a very nice script to show what u needs.


    #get mailboxes and iterate through each email address and shows it either primary or an alias
    
    get-mailbox | foreach{ 
    
     $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
    
     for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
     {
        $address = $_.EmailAddresses[$i]
        
        $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
     
        if ($address.IsPrimaryAddress)
        { 
        	$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
        }
       else
       {
        	$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Alias`n")
        }
     }
    }



    Save this entire script as a .ps1 file (Powershell script file) e.g "ShowEmailIDs.ps1", and then place it in the "Scripts" folder in MS Exchange Installation folder which is noramlly "C:\Program Files\Microsoft\Exchange Server\Scripts". Then open Exchange Management Shell and just type the name of .ps1 file e.g.  ShowEmailIDs.ps1 and press enter. It will show result like this

    User Name: Administrator
    mbx1@domain.com     Alias
    Administrator@domain.lab      Primary Email Address

    User Name: mailbox1
    mbx2@domain.com     Alias
    mailbox1@domain.lab   Primary Email Address

    Note: U can also put a filter for get-mailbox in above mentioned script to run this script for a specific domain like this

    get-mailbox | Where{ $_.PrimarySmtpAddress -like "*domain.lab" }| foreach{

    Regards,



    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    • Proposed as answer by Laeeq Qazi Monday, February 22, 2010 9:32 AM
    • Marked as answer by emma.yoyo Wednesday, February 24, 2010 1:22 AM
    Saturday, February 20, 2010 10:43 PM

All replies

  • Hi,

    Is this you are looking for?

    get-mailbox | select -expand emailaddresses alias
    Regards from www.windowsadmin.in
    • Marked as answer by emma.yoyo Wednesday, February 24, 2010 1:22 AM
    • Edited by ManU PhiliP Monday, July 28, 2014 6:49 AM
    Thursday, February 18, 2010 4:21 AM
  • Hi,

    Here is a very nice script to show what u needs.


    #get mailboxes and iterate through each email address and shows it either primary or an alias
    
    get-mailbox | foreach{ 
    
     $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
    
     for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
     {
        $address = $_.EmailAddresses[$i]
        
        $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
     
        if ($address.IsPrimaryAddress)
        { 
        	$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
        }
       else
       {
        	$host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Alias`n")
        }
     }
    }



    Save this entire script as a .ps1 file (Powershell script file) e.g "ShowEmailIDs.ps1", and then place it in the "Scripts" folder in MS Exchange Installation folder which is noramlly "C:\Program Files\Microsoft\Exchange Server\Scripts". Then open Exchange Management Shell and just type the name of .ps1 file e.g.  ShowEmailIDs.ps1 and press enter. It will show result like this

    User Name: Administrator
    mbx1@domain.com     Alias
    Administrator@domain.lab      Primary Email Address

    User Name: mailbox1
    mbx2@domain.com     Alias
    mailbox1@domain.lab   Primary Email Address

    Note: U can also put a filter for get-mailbox in above mentioned script to run this script for a specific domain like this

    get-mailbox | Where{ $_.PrimarySmtpAddress -like "*domain.lab" }| foreach{

    Regards,



    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    • Proposed as answer by Laeeq Qazi Monday, February 22, 2010 9:32 AM
    • Marked as answer by emma.yoyo Wednesday, February 24, 2010 1:22 AM
    Saturday, February 20, 2010 10:43 PM
  • Laeeq,

    How can I filter the output so that the address only SMTP without the X400 or any other protocols ?


    /* Server Support Specialist */

    Thursday, January 10, 2013 1:00 AM
  • Laeeq,

    How can I filter the output so that the address only SMTP without the X400 or any other protocols ?


    /* Server Support Specialist */

    Hi,

    You can filter the mailboxes, based on EmailAddresses property like this:

    
    
    get-mailbox -Filter {EmailAddresses -notlike '*X400:*' -and EmailAddresses -notlike '*X500:*'} -ResultSize Unlimited | foreach{ #processing here}

    Or to just get all mailboxes, which don't have X500 email addresses

    get-mailbox -Filter {EmailAddresses -notlike '*X500:*'} -ResultSize Unlimited | foreach{ #processing here}

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com

    Thursday, January 10, 2013 3:21 PM
  • Excellent script. How do I export the output into a .csv file?
    Monday, March 24, 2014 1:37 PM
  • Add | Export-csv C:\temp\exportfilename.csv right after get-mailbox.  Should look like this:

    get-mailbox | Export-csv C:\temp\aliases.csv | foreach{ 

     $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")

     for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
     {
        $address = $_.EmailAddresses[$i]
        
        $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
     
        if ($address.IsPrimaryAddress)
        { 
        $host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
        }
       else
       {
        $host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Alias`n")
        }
     }

    Tuesday, May 27, 2014 6:01 PM
  • When adding the export-csv right after you get the results of the full get-mailbox, not the results of the foreach loop.

    My understanding is that you can't export a foreach loop to a pipeline.  I tried using the ForEach-Object cmdlet, but not results are exported to CSV.  Here is what I tried.

    get-mailbox | ForEach-Object { 
    
     $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, "`nUser Name: " + $_.DisplayName+"`n")
    
     for ($i=0;$i -lt $_.EmailAddresses.Count; $i++)
     {
        $address = $_.EmailAddresses[$i]
        
        $host.UI.Write("Blue", $host.UI.RawUI.BackGroundColor, $address.AddressString.ToString()+"`t")
     
        if ($address.IsPrimaryAddress)
        { 
        $host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Primary Email Address`n")
        }
       else
       {
        $host.UI.Write("Green", $host.UI.RawUI.BackGroundColor, "Alias`n")
        }
     }
    }  | Export-Csv -NoTypeInformation c:\alias.csv
    How can this be completed so that the results are exported to the csv?

    Regards,
    BrianSW2337

    Tuesday, July 1, 2014 5:47 PM
  • I found the following example, this worked perfectly.  Much thanks to Chris at FlamingKeys.com for posting!

    http://flamingkeys.com/2011/07/how-to-list-or-export-all-email-aliases-in-exchange-20072010-using-powershell/

    # Create an object to hold the results
    $addresses = @()
    # Get every mailbox in the Exchange Organisation
    $Mailboxes = Get-Mailbox -ResultSize Unlimited
     
    # Recurse through the mailboxes
    ForEach ($mbx in $Mailboxes) {
        # Recurse through every address assigned to the mailbox
        Foreach ($address in $mbx.EmailAddresses) {
            # If it starts with "SMTP:" then it's an email address. Record it
            if ($address.ToString().ToLower().StartsWith("smtp:")) {
                # This is an email address. Add it to the list
                $obj = "" | Select-Object Alias,EmailAddress
                $obj.Alias = $mbx.Alias
                $obj.EmailAddress = $address.ToString().SubString(5)
                $addresses += $obj
            }
        }
    }
    # Export the final object to a csv in the working directory
    $addresses | Export-Csv addresses.csv -NoTypeInformation

    Regards,
    BrianSW2337

    • Proposed as answer by blainekehl Tuesday, August 23, 2016 10:51 PM
    Tuesday, July 1, 2014 6:10 PM
  • This solved what I needed to accomplish.

    Monday, July 15, 2019 3:34 PM