PowerShell Get-Mailbox display SMTP addresses

A question was posed recently where a user wanted to see a list of all his mailboxes, with their server, primary SMTP address, and any additional SMTP addresses associated with the mailbox. The user specifically wanted ONLY SMTP addresses.

With the help of a scriptblock, I was able to solve this on one line:

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


(I got the scriptblock idea from Xaegr’s comment on  http://dmitrysotnikov.wordpress.com/2010/01/25/select-object-with-subproperties)

Let’s break this line down:

First, we get all mailboxes (Get-Mailbox –ResultSize Unlimited

We pipe the results to Select-Object, where we select the DisplayName, ServerName, PrimarySMTPAddress, and then create the scriptblock to gather all secondary smtp addresses (The Primary SMTP address has a PrefixString of “SMTP” all others are a lower case “smtp”):

@{Name=”EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}

This results in the following for me:

DisplayName    ServerName    PrimarySmtpAddress        EmailAddresses
Mitschke, Karl   Server1            KMitschke@contoso.com    karlmitschke@contoso.com

Hint: Add | Export-Csv <csv file> –NoTypeInformation to save the results.

This is tested on Exchange 2007 SP2 and Exchange 2010.

  1. #1 by leo on April 14, 2010 - 14:13

    Thanks i spend 2 hour looking for this solution!


  2. #3 by Rihatum on June 30, 2010 - 16:09

    Hi Karl,

    Great blog, Great Scripts, very very helpful and you have given explanation too ; so that makes it easier to understand and to learn upon it.

    I have used this script just now to get a list and it works 🙂

    Now, I am getting event id 9327 and someone mentioned to check the Email address and AD mail address which doesn’t matches for some or one user and then you see those users disappearing from GAL.

    Is there a way with your script you can add something so it list AD MAIL ADDRESS too ?

    I hope that’s ok ?
    Once again thanks for a great resource for people like me
    Kind Regards

  3. #4 by karlmitschke on July 1, 2010 - 14:16


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

    • #5 by Rihatum on July 5, 2010 - 00:25

      Hi Karl,

      Thanks so much for a prompt response, I tried the script and it works !!

      It is listing the AD Email address too, which is different from the Primary SMTP Address, how can we change that AD Address to match it to the smtp address ?

      Can you provide a link to some background info, my googling hasn’t taken me far yet so a bit stuck here.

      Once again thanks so much for this wonderful script.

      One more quesiton, your another script of Exchange DB Reporting, do we need to change something in it so it checks for specific Exchange server (I have only ONE at the moment) ??

      Kind Regards

  4. #6 by Sven on August 3, 2010 - 12:54

    Great one-liner, but any idea on how to make the columns wider so you can export this to a txt file and maintain the address instead of getting dozens of …. in your table?



    • #7 by karlmitschke on August 3, 2010 - 16:54


      Is the | Export-Csv –NoTypeInformation not working for you?

  5. #8 by Tony on August 21, 2010 - 18:54

    What if you just wanted an output of emails that ONLY contained secondary smtp addresses.

    • #9 by karlmitschke on August 24, 2010 - 22:21


      Try this:
      Get-Mailbox -ResultSize Unlimited |Where-Object {$_.EmailAddresses -clike “smtp*”} |Sele
      ct-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={$_.EmailAddresses |Where-Object
      {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}


  6. #10 by Dan Soares on August 24, 2010 - 15:47


    Thank so very much for sharing this script. I seem to be getting unusual results.

    When I run the following I see that some users display both Primary and Secondary emails (under Emailaddresses). That indicates to me that they DO have secondary emails.

    Get-Mailbox -resultsize unlimited | Select-Object displayname,emailaddresses |Export-Csv -path $filename –NoTypeInformation

    However when I run your script, that column in the csv file is blank

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

    I don’t understand it. Would you be able to assist me by suggesting how I can troubleshoot the problem?

    Thanks in advance,


    • #11 by karlmitschke on August 24, 2010 - 22:12

      I get the same results on my workstation, running a remote session to one of my Exchange 2010 HT servers.
      On that HT, I get the expected results.

      Can you test this on an Exchange server?


    • #12 by Serge de troyer on November 14, 2011 - 07:08

      Good aftrenoon,

      I just found the information you posted. They are really nice. I tried to use the following:

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

      It works nearly perfectly, I miss certainly something. It gives me a file (I tried with a txt or csv file), but It truncates all the aliases to 25 characters followed by dots.
      Here the result for myself:

      Serge De Troyer zeus serge@ngroup.be {serge@nostalgie.be, serge…

      What I really need is the list … after the dots. I have about 80 mailboxes with many aliases. The problem is to find which aliases are already distribituted and to whom.

      Do you have an idea what I should modify to have all the existing aliases to all the mailboxes?

      Many thanks already

      Best regards

      Serge De Troyer

      • #13 by Karl Mitschke on November 14, 2011 - 09:12

        Try replacing > c:\mailbox_alias.txt with | Export-Csv c:\mailbox_alias.csv

      • #14 by Serge de troyer on November 16, 2011 - 04:43

        Great! I type

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

        and I have at least all aliases in an Excel file. Il have to create a small macro to have all in nice columns, because every name is actually in one cell, BUT the information is available.

        Very Great. Thanks


  7. #15 by Dan Soares on August 25, 2010 - 13:28

    Thanks for replying. We don’t have an Exchange server in house but I am running the PS script against the Live@edu Exchange server which hosts our student accounts.

    Curiously, the following script returned what I needed:

    Get-Mailbox -ResultSize Unlimited |Select Name, PrimarySMTPAddress, @{Name=’EmailAddresses’;Expression={[string]::join(“;”, ($_.EmailAddresses -cmatch ‘smtp’))}}

    Dunno why THIS script worked but not the other. I then parsed the output to extract the email address from the resulting string.


  8. #16 by Jason R on February 22, 2011 - 08:26

    Thank You for this script! I used Get-Recipient in order to get everything with an e-mail address. Worked like a charm!

  9. #17 by Joe on February 22, 2011 - 14:50

    Thanks for the post.

    I am trying to get my users data, firstname,lastname, and customattribute1 but cant in my query.

    I am using Live@edu also, any ideas?

    • #18 by Karl Mitschke on February 24, 2011 - 13:39

      Get-Mailbox does nor return Firs Name and Last Name. Try Get-Recipient with a filter of recipienttype = UserMailbox:
      (All on one line again)
      Get-Recipient -Filter {RecipientTypeDetails -eq “UserMailbox”} -ResultSize Unlimited | Select-Object FirstName, Lastname, CustomAttribute1, DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}


      • #19 by Joe on March 3, 2011 - 08:51

        I tried the above code and it threw an error – I have a live @ edu enviorment, not hosted exchange

        Here is my error

  10. #20 by Joe on March 3, 2011 - 08:36

    Wow thanks for that!

    Do you know if there is a way to set the country/region?
    My problem is when i create a new account, and the user logs in for the first time, they have to enter there date of birth, and select a county/region.
    Can i set this?

    I am using a live @ edu enviorment.

  11. #21 by Kris on March 14, 2011 - 09:55

    I have a question….what if I need to only get email address based off a csv file, how would I do that? I get a CSV file of users I need to create after they are created I need to export the email address back to another person. Any help would be greatly appreciated!!

  12. #22 by Kris on March 14, 2011 - 10:10

    For example would this work?

    Import-Csv “\\server.domain.local\c:\NewStudents\ex_export_for_account_creation.csv” | foreach { Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”}| ForEach-Object {$_.SmtpAddress}}} |Export-Csv -path C:\EmailReport\EmailReport.csv –NoTypeInformation

    the csv file that I am importing is not locally on the Exchange server it is on our PDC.

    • #23 by Karl Mitschke on April 5, 2011 - 10:47

      I’d do this as:

      $UserData = @()
      foreach ($user in Import-Csv "\\server.domain.local\c:\NewStudents\ex_export_for_account_creation.csv")
      $UserData += Get-Mailbox $user.alias |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”}| ForEach-Object {$_.SmtpAddress}}}
      $UserData | Export-Csv -Path C:\EmailReport\EmailReport.csv –NoTypeInformation


  13. #24 by Robert on March 28, 2011 - 10:12

    Nice cmdlet. Is there any way to adapt this to public folders? I’ve tried a few ways, but keep getting errors.

    Any advice would be great.


    • #25 by Karl Mitschke on April 5, 2011 - 10:41

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

  14. #26 by Narayana on May 3, 2011 - 13:00

    Excellent cmdlet. Worked like a charm.

    Thank you

    • #27 by albertwt on April 15, 2013 - 19:36

      Hi Karl,

      Thanks for sharing the script here, however how to suppress the warning message below in the result ?

      WARNING: Object domain.com/Microsoft Exchange System Objects/Server Production has been corrupted and it is in an inconsistent state. The following validation errors have occurred:
      WARNING: “Server Production” is not valid for Alias. Valid values are: Strings formed with characters from a to z (uppercase or lowercase), digits from 0 to 9, !, #, $, %, &, ‘, *, +, -, /, =, ?, ^, _, `, {, |, } or ~. One or more periods may be embedded in an alias, but each one of them should be preceded and followed by at least one of the other characters. Unicode characters from U+00A1 to U+00FF are also valid in an alias, but they will be mapped to a best-fit US-ASCII string in the email address which is generated from such an alias.


      • #28 by albertwt on April 15, 2013 - 20:24

        ok, I found it myself using the -WarningAction SilentlyContinue -ErrorAction SilentlyContinue after the Get cmdlet 🙂

  15. #29 by Randy on June 3, 2011 - 08:34

    This is some great stuff. Can you guys tell me how to breakdown the DisplayName portion of this? In other words, when I export to a csv file, the DisplayName shows up as one column with LastName, FirstName format. I need two columns to split the DisplayName so it shows the first column as FirstName then the second column LastName. I tried using GivenName, Surname but no joy.


    • #30 by Karl Mitschke on June 9, 2011 - 10:26


      This uses PowerShell V2’s splatting:
      $Mailbox = @{
      ResultSize = “Unlimited”
      $Filter = @{
      FilterScript = {$_.PrefixString -ceq “smtp”}
      $Select = @{
      Property = @{Name=”First Name”;Expression={$_.DisplayName.Split(“,”)[1].Trim()}},
      @{Name=”Last Name”;Expression={$_.DisplayName.Split(“,”)[0].Trim()}},
      @{Name=”EmailAddresses”;Expression={$_.EmailAddresses | Where-Object @Filter}}
      Get-Mailbox @Mailbox | Select-Object @Select


  16. #31 by Randy on June 10, 2011 - 06:35

    Fantastic! Thanks Karl.

  17. #32 by Chris Maive on July 5, 2011 - 07:07

    Fantastic Script!

    All our users have a primary email address of @examplea.com and within the secondary email address list they have one ending @exampleb.com.

    We want to promote @exampleb.com address as the new Primary and demote the current primary @examplea.com to Secondary.

    Is this possible in Powershell?

    Thanks, Chris

  18. #33 by Dave on July 8, 2011 - 11:03

    Karl, great script. Now what I need to do is somehow filter the smtp addressess by a certain criteria, i.e smtp address is equal to SamAccountName@company.com. Any thoughts?

  19. #34 by RichardM on July 28, 2011 - 06:00

    Hi, the script is working perfect for me – is there a way to only output AD accounts that are enabled?

  20. #35 by Tim on August 5, 2011 - 09:06

    Does this Script show Distribution List Addresses?

    • #36 by Karl Mitschke on August 8, 2011 - 10:57

      Modify the script as following, and it will show distribution lists:
      Get-DistributionGroup -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}

  21. #37 by Robert on August 9, 2011 - 09:39

    Karl Thank you so much for the script!

    How could I modify the script to take input from a CSV to lookup which accounts use a certain SMTP address?

    • #38 by Karl Mitschke on August 9, 2011 - 10:29

      Assuming your csv has the user alias, with the header “Alias”

      Using powerShell v2 splatting:

      Foreach ($Mailbox in Import-Csv c:\scripts\users.csv)
      $Property = @{
      Property = 'DisplayName','ServerName','PrimarySmtpAddress',
      @{Name="EmailAddresses";Expression={$_.EmailAddresses | `
      Where-Object -FilterScript {$_.PrefixString -ceq "smtp"} | `
      Where-Object -FilterScript {$_.PrefixString -ceq "smtp"} | `
      ForEach-Object -Process {$_.SmtpAddress}}}
      Get-Mailbox -Identity $Mailbox.Alias | Select-Object @Property


  22. #39 by FredC on August 26, 2011 - 01:15

    Wonderfull script, it give me solution to set more smtpaddress.
    So, I am surprised that I cannot list the custom address when I remove the condition {$_.PrefixString -ceq “smtp”} ! Do you have any tips for listing SIP, x400 and X500 address?
    Thanks for your support.

    • #40 by Karl Mitschke on August 29, 2011 - 09:20

      Try this:
      Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses}}


  23. #41 by Hari on August 29, 2011 - 06:47

    Hi Karl,

    i am trying to pull out information of all the Mailboxes from exchange 2010, with Displayname,Email address, Company,Department and along with move history. currently i m geting all the info from seperate commands, using get-maibox, get-user & get-mailboxstatistics i get all the info, but i would require to combine it into a simple script like you do into a csv file Thanks in advance

    • #42 by Karl Mitschke on August 29, 2011 - 09:26


      That’s outside ths scope of this article.
      You could email me and I will look into this.


  24. #43 by Lars B. on September 6, 2011 - 09:05


    Thank you for this wonderfull post. The script runs ok but I’m not able to get secondary smtp addresses. It only exports the PrimarySMTPAddress of the users. My script looks like this:

    Get-Mailbox -OrganizationalUnit “OU Name” | Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={$_.EmailAddresses | Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_SmtpAddress}}} | Export-Csv C:\PSscripts\”filename”.csv -NoTypeInformation

    Any ideas?

    – I have tried to run the script on a MBX server as well as an Exchange management tools server.

    I hope someone can assist me here.

    Thank you very much.

    Lars Bengtsson.

    • #44 by Karl Mitschke on September 20, 2011 - 14:02


      Modify the ForEach-Object to “$_.SmtpAddress”

      Note the “.” after the “$”


  25. #45 by Jeremy on October 25, 2011 - 10:05

    Hi Karl

    Thanks for the script, works very well. Would you know if its possible to filter for a specific domain ? our office uses @domaina.co.uk and @domainb.co.uk but would be handy to list all @domaina.co.uk



    • #46 by Karl Mitschke on October 25, 2011 - 11:05

      Try this:
      Get-Mailbox -Filter {UserPrincipalName -like “*@domaina.co.uk”} |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}


  26. #47 by Eric on November 1, 2011 - 17:34

    Great script, is there anyway to output it in alphabetic order?

    • #48 by Karl Mitschke on November 2, 2011 - 07:57

      Add a Sort-Object cmdlet down the pipeline like one of the following:
      | Sort-Object -Property DisplayName
      | Sort-Object -Property PrimarySmtpAddress

  27. #49 by Moazzam on November 2, 2011 - 22:21

    hi how to save the result in a text or csv file?

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

    and to include distribution boxes, users etc.


  28. #50 by Moazzam on November 2, 2011 - 22:31

    ok this works perfect:

    Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv C:\”filename2”.csv -NoTypeInformation

    now how to get same results for all distribution mail boxes etc. as this is not showing distribution mail boxes and its email addresses

  29. #51 by Moazzam on November 2, 2011 - 22:55

    worked it out.

    Get-DistributionGroup -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv C:\”filename3”.csv -NoTypeInformation

  30. #53 by cr1x on November 10, 2011 - 08:36

    what can I do if I want to put the PrimarySMTPAddress (Without a headline or anything) into a variable for use later?

    ie a parameter for another function like set-mailbox or something

    • #54 by Karl Mitschke on November 14, 2011 - 09:10

      Unless I miusunderstand your question, try this:

      $emailaddresses += Get-Mailbox -ResultSize Unlimited | Select-Object -Property PrimarySMTPAddress


  31. #55 by Dean on December 6, 2011 - 00:54

    Is there any way to have each of the secondary email addresses in their own column?

    • #56 by Karl Mitschke on December 6, 2011 - 09:50

      You could, but it’s beyond the scope of this one liner – let me work on it for a while…

  32. #57 by ECW on December 6, 2011 - 19:57

    Hi, anyone have a good way to do a search where the results show any mailbox that -lacks- a certain alias format? Say you want to make sure everyone has username@mail.domain.com ; so you wish to do a search that ensures everyone has (rather than manually ensure everyone has the policy applied.)


    • #58 by Karl Mitschke on December 7, 2011 - 13:52

      Try this:
      Get-Mailbox -Filter “emailaddresses -notlike ‘*@mail.domain.com'”

      • #59 by Fox W. on December 7, 2011 - 15:53

        Thank you so much for the help, it just needed to be piped through from get-mailboxdatabase, here is what worked:

        Get-MailboxDatabase | Get-Mailbox -Filter “emailaddresses -notLike ‘*@mail.domain.com'”

  33. #60 by Shareef Yoosuf on February 14, 2012 - 23:26

    Thanks man!

  34. #62 by Juan Manuel. on February 24, 2012 - 20:31

    Hi all,
    is there any way to list all the available domains ( @”domain.com” –>only the info between “..”) listed in the primary smtp email address of all the users?

    Thank you!!

    • #63 by Karl Mitschke on March 5, 2012 - 15:03

      If I understand you right, try
      Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,@{Name=“PrimarySmtpAddress”;Expression={$_.PrimarySmtpAddress.Domain}}


  35. #64 by jmgomez85 on February 27, 2012 - 16:45

    is there a way to obtain all the domains that my organization is using in all the user accounts? I mean, list all the users and display name, and the domains that they are using in their primary and secondaries email addresses.

    Thanks in advance for your help!!

    • #65 by Karl Mitschke on March 5, 2012 - 14:59

      A quick way would be:
      Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,@{Name=“PrimarySmtpAddress”;Expression={$_.PrimarySmtpAddress.Domain}}, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {($_.SmtpAddress).Split(“@”)[1]}}}


  36. #66 by bostjanc on March 7, 2012 - 07:26

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

    would be pulling e-mail adresses from PRIMARY and also CHILD domain in FOREST?
    with best regards

  37. #68 by Bonnie on June 4, 2012 - 14:08

    Hi, I want to put just the email address of into a variable and what you wrote aboce doesn’t work
    get-mailbox “user” |select-object -property PrimarySMTPAddress So I need the email address only and not the header primarySMTPaddress, tried a .value but that didn’t work.


    • #69 by Karl Mitschke on June 7, 2012 - 12:23

      Try this:
      $email = (get-mailbox “user” |select-object -ExpandProperty PrimarySMTPAddress).ToString()

  38. #70 by frank on June 28, 2012 - 10:10

    I’m not sure if this thread is still active. As others have said, this was a very helpful post. What does it take to format the secondary addresses to have them listed with a comma for easier import ?

    • #71 by Karl Mitschke on June 29, 2012 - 08:28

      It’s ugly, but this one line script will do it:

      (Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}) |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses.Split() -join(“,”)}} |Export-Csv C:\scripts\temp\addresses2.csv -NoTypeInformation


  39. #72 by frank on July 2, 2012 - 12:06

    Hi Karl,

    Thanks for the quick reply. When I run this I get the following error:

    You must provide a value expression on the right-hand side of the ‘-‘ operator.
    At line:1 char:350
    + (Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={$_.EmailAddresses |Where-Object
    {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}) |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=”EmailAddresses”;Expression={$_
    .EmailAddresses.Split() -j <<<< oin(",")}} |Export-Csv C:\scripts\temp\addresses2.csv -NoTypeInformation (Get-Mailbox -ResultSize Unlimited |Select-Object DisplayN
    ame,ServerName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddre
    ss}}}) |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name="EmailAddresses";Expression={$_.EmailAddresses.Split() -join(",")}} |Export-Csv C:\scripts\
    temp\addresses2.csv -NoTypeInformation (Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name="EmailAddresses";Express
    ion={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}}) |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @
    {Name="EmailAddresses";Expression={$_.EmailAddresses.Split() -join(",")}} |Export-Csv C:\scripts\temp\addresses2.csv -NoTypeInformation

    • #73 by Karl Mitschke on July 2, 2012 - 15:12

      I’m not seeing that error here….
      I assume you copied and pasted directly to a console?
      Can you paste it into notepad or another editor and make sure there are no weird characters around the -join?

      • #74 by frank on July 13, 2012 - 09:39

        Thanks for checking on this, I can’t find the character if it’s in there. I threw it in Notepad++, and nothing. Any other ideas ?

  40. #75 by Hitesh on August 23, 2012 - 13:26

    Hi Karl…
    I have two global AD’s A & B, A have only Primary Addresses for all users and B have Primary + Secondary Addresses.
    I am looking for a power shell script which can compare Primary Addresses and add Secondary Addresses with respective Primary SMTP.

    I appreciate your help on this.

    Let me know if need any other information.

    • #76 by Karl Mitschke on August 24, 2012 - 11:15

      I see you have asked for help on the TechNet and PowerShellCommunity forums, so I will see what I can do to help you there.

  41. #77 by Alex Edwards on October 8, 2012 - 08:24

    Very neat and useful script. Thanks for posting it

  42. #79 by Jose on December 13, 2012 - 15:19

    i receive error
    “The term ‘Get-Mailbox’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
    spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:12
    + Get-Mailbox <<<< -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name="EmailAddres
    ses";Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}}
    + CategoryInfo : ObjectNotFound: (Get-Mailbox:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException"

    • #80 by Karl Mitschke on December 31, 2012 - 10:15


      You need to have the Exchange Management Shell loaded.


  43. #81 by Roger on January 3, 2013 - 20:08

    Hi Karl,
    Do you know an Power Shell script that will Query Disabled Active Directory user accounts on a domain and compare them to the Exchange Global Address List and display the Disabled AD accounts with Unhidden addresses in the GAL? I ask this question because we have Terminated Employees still showing in the GAL because the mailboxes were never deleted or hidden in Exchange 2010. I would like to generate a report to clean up the GAL. Thank You in advance. Roger

    • #82 by Karl Mitschke on January 4, 2013 - 09:55

      This might be what you are looking for:
      Get-Mailbox -Filter {UserAccountControl -eq 514 -and HiddenFromAddressListsEnabled -eq $false}

      • #83 by roger on January 4, 2013 - 11:37

        You are a sctipting mastermind. Thank You! Much Appreciated!

  44. #84 by Donovan on January 18, 2013 - 01:40

    Thank you very much this worked without any alterations. Quick solution!

    • #85 by Karl Mitschke on January 18, 2013 - 07:56

      you are welcome.

      I’m glad you found it of use.

  45. #86 by Marcin Liskiewicz on March 20, 2013 - 03:52


    I heave in smtp primary adress like this (fn.ln@domain.com and fn.ln2@domain.com).
    How to export only users to heave “fn.ln2@domain.com” ??

    Marcin Liskiewicz

    • #87 by Karl Mitschke on June 19, 2013 - 13:44

      If you are only worried about email addresses with a 2@domain.com, this should work:
      Get-Mailbox -ResultSize Unlimited -filter {emailaddresses -like “*.*2@domain.com”} |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}}


  46. #88 by Aziz on May 10, 2013 - 04:55

    This worked for me as well. Excellent article and the added follow-up and tweaking per the questions you receive it also great. This was just what I needed I just had to add the IgnoreDefaultScope switch, so that it showed my whole organization. Thanks again.

  47. #89 by Tim Norton on July 11, 2013 - 11:58

    Hi Karl,
    I am needing a powershell script that will remove smtp addresses imported from a csv file. We are using Exchange 2007. The addresses we are needing to remove are from name changes over the last few years. Any help would be appreciated.

    • #90 by Karl Mitschke on August 2, 2013 - 13:58

      You could do it this way, IF you are running Exchange 2010 or 2013:
      Set-Mailbox -EmailAddresses @{Remove=”oldalias@olddomain.com”,”oldalis2@realolddomain.com”}

      • #91 by Karl Mitschke on August 2, 2013 - 14:00

        So, if I learned to read, I’d see you are on Exchange 2007. So, the second method (or the recipient policy) I posted should work.

  48. #92 by Tim Norton on July 11, 2013 - 12:13

    Following up on my previous question: I have read that you can remove an address by omitting it from the Set-Mailbox command. Since our standard email address format is alias@domain.com, would it be easier to run a script from csv on all users to Set-Mailbox with SMTP address that matches alias name thus removing the unneeded addresses?

    • #93 by Karl Mitschke on August 2, 2013 - 13:59

      Yes, you should be able to do this:
      Set-Mailbox -EmailAddresses alias@domain.com

      Or, modify and apply the recipient policy to all mailboxes…


  1. smtp help » Blog Archive » SMTP RFC – RFC 2821 – Part 6
  2. What is the Primary SMTP email address « AIMOO TODAY
  3. Exchange Powershell: Remove e-mail address from address list « Steve Hardie.com
  4. How to get a list of SMTP addresses from Exchange 2010 | The-IT-Blog
  5. Export SMTP Email Addresses within Exchange 2007/2010 | Admin Corner

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: