skip to Main Content

Export a list of mailboxes to CSV in Exchange

You need to export a list of mailboxes to a CSV file in Exchange Server. Such a list can be important. For example, there is a mailbox migration coming. With that list, you can get more information about the mailboxes of the users. In this article, you will learn how to do it with PowerShell.

Export a list of mailboxes to CSV through PowerShell

The information you need to export is:

  1. DisplayName
  2. SamAccountName
  3. PrimarySMTPAddress

Before you start the export to a CSV file, you can make use of the Out-GridView cmdlet. This cmdlet will give you the results without exporting. I recommend doing that first. Let’s see it in action.

Run Exchange Management Shell as administrator. Use the Get-Mailbox cmdlet, including the ResultSize parameter. The output will list only 10 users. Therefore, it will generate faster without a load on the server.

[PS] C:\>Get-Mailbox -ResultSize 10 | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Out-GridView
WARNING: There are more results available than are currently displayed. To view them, increase the value for the ResultSize parameter.
Export a list of mailboxes to CSV in Exchange out-gridview

You can sort the output on email address.

[PS] C:\>Get-Mailbox -ResultSize 10 | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Out-GridView
WARNING: There are more results available than are currently displayed. To view them, increase the value for the ResultSize parameter.

Now that you can confirm that the information is correct. You can change the command to Resultsize Unlimited.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Out-GridView

If all is looking great, let’s export the information to a CSV file. First, make sure you have a folder created on your C: drive with the name output. The path in Windows Explorer should show as C:\output\.

[PS] C:\>Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Export-CSV c:\output\display_sam_smtp.csv -NoTypeInformation -Encoding UTF8

CSV file export is complete.

Result exported list of mailboxes to CSV

Go to the path c:\output\display_sam_smtp.csv.

Open the CSV file with your favorite application. For example, I opened the CSV file with Microsoft Excel.

Export a list of mailboxes to CSV in Exchange open csv file

That’s it. Export a list of mailboxes to CSV in Exchange Server completed.

Conclusion

In this article, you learned how to export a list of mailboxes to CSV in Exchange. Use the Out-GridView cmdlet before exporting it to a CSV file. Did you use the PowerShell command to export a list of mailboxes to CSV in Exchange?

Did you enjoy this article? You may also like List all SMTP addresses with PowerShell. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 4 Comments

  1. Good Morning Ali,

    Do you have a script that can export mailboxes for a specific database or just 1 mailbox eg MBexch1DB

    Thanks
    Sandile

    1. Hi Sandile,

      You can use the -Database parameter to filter the results by mailbox database.

      Example:
      Get-Mailbox -Database “DB01” -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress | Sort-Object PrimarySmtpAddress | Export-CSV c:\output\display_sam_smtp.csv -NoTypeInformation -Encoding UTF8

      Change DB01 to your mailbox database.

      Read more in the article List mailboxes in Exchange database with PowerShell.

Leave a Reply

Your email address will not be published. Required fields are marked *