Updated 11 hours ago

Export All Mailboxes in Microsoft 365 Using PowerShell

by Praba

5 min read

No Comments

Managing Exchange Online mailboxes is one of the most essential responsibilities for Microsoft 365 administrators. Whether you’re conducting audits, offboarding M365 users, or handling routine mailbox maintenance, having quick access to a complete and accurate list of mailboxes is vital. In this blog, we’ll walk you through the different ways to export mailboxes in Exchange Online.

How to Get All Mailboxes in Exchange Online?

Microsoft 365 offers multiple ways to export mailbox data, each with its own use case and convenience level. Let’s dive into each method.

Get a List of Mailboxes in Exchange Online Admin Center

The Exchange Admin Center (EAC) provides a clean, user-friendly interface for viewing and exporting mailbox data. This method is ideal for administrators who prefer a graphical interface over scripting.

  1. Sign in to the Exchange admin center.
  2. Navigate to Recipients –> Mailboxes.
  3. Use the Filter option to view desired list of mailboxes (user mailboxes, shared mailboxes, archived mailboxes, litigation hold mailboxes)
  4. Click the Export icon to download the data as a CSV file.

Export all mailboxes in Exchange Online

Export Mailboxes with a Single PowerShell Cmdlet

For administrators handling large environments, PowerShell offers a more flexible and scalable way to get mailbox details in Microsoft 365. To retrieve all mailboxes in organization, run the following after connecting to Exchange Online PowerShell module.

This command fetches all user and shared mailboxes from Exchange Online. However, to export this data to a CSV file, you’ll need to add the Export-Csv cmdlet.

By running the above, admins can retrieve all mailboxes and exports them into a file named Mailboxes.csv.

Alternatively, you can use the ‘Get-EXOMailbox’ cmdlet to retrieve bulk mailboxes faster in large environments.

While using the EAC or a simple PowerShell command works for basic needs, they can become limiting when dealing with larger datasets, applying advanced filters, or needing consistent formatting across exports. To streamline this process, we came up with a custom PowerShell script to report on all mailboxes with additional benefits such as handling multiple mailbox types and formatting the output neat.

Download Script: GetMailboxes.ps1

Script Highlights

  • The script automatically verifies and installs Exchange Online PowerShell module (if not installed already) upon your confirmation.
  • Exports all mailboxes in the organization.
  • Allows exporting mailboxes that matches the selected filter.
    • User Mailboxes
    • Shared Mailboxes
    • Room Mailboxes
    • Equipment Mailboxes
  • Export the report result to CSV.
  • The script can be executed with MFA enabled account.
  • It can be executed with Certificate-based Authentication (CBA) too.
  • The script is schedular-friendly.

Script Execution

The ‘All mailboxes in Exchange Online’ report looks like below.

Get Mailboxes in Microsoft 365

The script exports all mailboxes in Microsoft 365 with the following attributes:

  • Mailbox Name
  • UPN
  • Alias
  • Mailbox Type
  • Primary SMTP Address
  • Other Email Addresses

Script Execution Methods

  1. Download the script.
  2. Start the Windows PowerShell.
  3. Select any of the methods provided to execute the script.

Method 1: Execute the script with MFA or non-MFA account.

Executing this script generates a comprehensive report of all Exchange Online mailboxes in the organization.

Method 2: Executing the script by explicitly mentioning credentials

The above method supports only non-MFA accounts. If the admin account has MFA, you need to disable MFA using CA policy to make this work.

Method 3: Run the script using certificate-based authentication.

To use the certificate-based authentication, you must register the app in Entra ID which helps you to connect Exchange Online using certificate. Depending on the requirements, you can use either CA certificates or create self-signed certificates.

You can also schedule this script using Task Schedular or Azure Automation to periodically export all mailboxes in Microsoft 365.

Get All Mailboxes in Exchange Online – More Use Cases

The script delivers a detailed Exchange Online mailbox report with filters to target specific mailbox types – user, shared, room, or equipment. Let’s see where it comes in handy.

List Only User Mailboxes in Microsoft 365

In large organizations, identifying only user mailboxes is crucial for compliance audits, user management, and security reviews. To generate a report that includes only user mailboxes, run the script with the –UserMailboxesOnly parameter.

This will return a list of all user mailboxes excluding shared, resource, or system mailboxes, allowing you to ensure proper user setup and compliance with internal policies.

Tip: You can also run a PowerShell script to export mailbox sizes and their quota limits for better mailbox management.

Export Shared Mailboxes in Exchange Online

Shared mailboxes are typically used by multiple users to access and manage the same mailbox. These are often users for team communication or to manage generic email addresses like support@contoso.com or sales@contoso.com.

To filter and view all shared mailboxes, run the following script with the –SharedMailboxesOnly parameter.

This will help you identify all shared mailboxes, making it easier to manage permissions and assign users to the correct shared resources.

Tips:

  1. For better compliance and visibility, try scripts that specifically extract licensed shared mailboxes and non-compliant shared mailboxes.
  2. Don’t forget to review shared mailbox size report for capacity planning. This helps ensure adequate storage, avoid disruptions, and implement effective archive and deletion policies.

Discover Microsoft 365 Room Mailboxes

Room mailboxes represent physical locations such as meeting rooms or conference areas that are available for booking and scheduling within Microsoft 365. These mailboxes are key in managing resources and ensuring that meeting spaces are available for your organization’s needs.

Execute the script with –RoomMailboxes parameter to view all room mailboxes in Microsoft 365 environment.

By using this filter, you can easily identify and manage all room mailboxes, enabling more efficient resource scheduling and meeting planning.

Beyond simply listing room mailboxes, it’s equally important to:

Note: Make use of a custom PowerShell script that goes beyond basic info to export 8 detailed room mailbox reports.

Fetch Equipment Mailboxes in Exchange Online

Equipment mailboxes are used for reserving assets such as projectors, vehicles, or laptops. Without regular audits, equipment mailboxes may remain in the system even if the assets are no longer in use. To retrieve a report of only equipment mailboxes, run the script with the –EquipmentMailboxesOnly parameter.

This report helps IT and facilities teams manage resource reservations effectively, identify underused or outdated assets, and maintain a clean, accurate Exchange environment.

I hope this blog helps you identify and export all mailboxes in Exchange Online effectively. If you have any queries, feel free to reach us through the comment section.

Share article