Skip to 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 users’ mailboxes. In this article, you will learn how to export a list of mailboxes to CSV file in Exchange with PowerShell.

Export a list of mailboxes to CSV with 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 use 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 by 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 and add Resultsize Unlimited to it.

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

If everything looks great, let’s export the information to CSV file. First, ensure a folder is created on the (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

The 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, with Microsoft Excel.

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

The CSV file with all the information looks great in Microsoft Excel.

Note: To export a mailbox size report, read the article Get mailbox size of all users in Exchange with PowerShell.

Conclusion

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 12 Comments

  1. Hello Ali,

    Your help is much appreciated, how do I included additional properties of each object in the script so it pulls the below info from each (mailbox)?
    ###############################################################################
    Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress, Imap, Pop, OWA, ActiveSync | Sort-Object PrimarySmtpAddress | Out-GridView

    im stuck at this part!!!!!!!!

    I need to export the below groups:

    DisplayName
    SamAccountName
    PrimarySMTPAddress
    Imap Enabled/Disabled
    Pop Enable/Disable
    OWA Enable/Disable
    Active Sync Enable/Disable

    1. Hi AJ,

      This is the command you need:

      Get-Mailbox -ResultSize Unlimited | Get-CASMailbox | Select-Object DisplayName, SamAccountName, PrimarySmtpAddress, IMAPEnabled, POPEnabled, OWAEnabled, ActiveSyncEnabled | Sort-Object PrimarySmtpAddress | Out-GridView
  2. Hola Ali como estas. Consulta que script puedo correr para listar los buzones entre determinada capacidad, ejemplo 1 GB y 1,5 GB, es para moverlos a otra base, gracias saludos desde Argentina.

    1. Hi Sebastian,

      You can use the following commands.

      Get all mailboxes in the Exchange organization between 1 GB and 1.5 GB:

      Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {($_.TotalItemSize -ge "1GB") -and ($_.TotalItemSize -le "1.5GB")} | Select-Object DisplayName, ItemCount, TotalItemSize

      Move the mailboxes to another database:

      $Move = Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {($_.TotalItemSize -ge "1GB") -and ($_.TotalItemSize -le "1.5GB")}
      $Move.DisplayName | New-MoveRequest -TargetDatabase "DB02"

      Get all mailboxes in particular Exchange mailbox database between 1 Gb and 1.5 GB:

      Get-Mailbox -Database "DB01" -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {($_.TotalItemSize -ge "1GB") -and ($_.TotalItemSize -le "1.5GB")} | Select-Object DisplayName, ItemCount, TotalItemSize

      Move the mailboxes to another database:

      $Move = Get-Mailbox -Database "DB01" -ResultSize Unlimited | Get-MailboxStatistics | Where-Object {($_.TotalItemSize -ge "1GB") -and ($_.TotalItemSize -le "1.5GB")}
      $Move.DisplayName | New-MoveRequest -TargetDatabase "DB02"
  3. Hi Ali,

    I can’t figure out how to reuse this script to include “last login time”. It doesn’t appear this is a parameter for get-mailbox, but open to your suggestions.

    Thanks

      1. Thank you Ali, greatly appreciate individuals like yourself who take the time to share their knowledge and skills with others.

  4. 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 articles:

      List mailboxes in Exchange database with PowerShell
      Get mailbox size of all users in Exchange with PowerShell

Leave a Reply

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