Often, Microsoft 365 admins want to export all email addresses in their Microsoft 365 environment. You can use the PowerShell cmdlets like Get-Mailbox, Get-Recipient to retrieve Primary email addresses and aliases. Since each type of mailbox requires different cmdlets or filtering conditions, it is always challenging to find the right one.
Since Microsoft allows sending emails from alias addresses, admins need a record of alias addresses. To easily export all the email addresses, you can download our script. Also, our script lets you use the built-in filtering params to retrieve the email addresses of each type of mailbox.
Script Download: GetAllOffice365EmailAddresses.ps1
- The script uses modern authentication to connect to Exchange Online.
- The script can be executed with MFA enabled account too.
- Exports report results to CSV file.
- Allows you to generate email address report for a specific mailbox type, such as user mailbox, shared mailbox, guest users, contacts, etc.
- Automatically installs the EXO V2 module (if not installed already) upon your confirmation.
- The script is scheduler friendly. I.e., Credential can be passed as a parameter instead of saving inside the script.
Export Microsoft 365 Email Addresses – Sample Output:
The exported report contains following attributes: Display Name, Recipient Type Detail, Primary SMTP Address, Alias Email Address.
Script Execution Steps:
To run the script, you can choose any one of the methods below.
Method 1: Execute the script with MFA and non-MFA accounts
Method 2: Execute the script by explicitly mentioning the credentials.
.\GetAllOffice365EmailAddresses.ps1 -UserName [email protected] -Password XXX
Note: Scheduling works only for non-MFA accounts. If the admin account has MFA, you need to disable MFA based on the Conditional Access policy to make it work.
More Use-cases of ‘Get All Office 365 Email Address’ PowerShell Script:
Our script supports multiple in-built advanced filtering parameters, which allows admins to view email addresses based on their requirements. With this script, you can
- Get all email addresses in Office 365
- Find the email address for user mailboxes
- Export shared mailboxes’ email addresses
- View distribution groups’ email addresses
- Find email addresses of the guest user
- Show email addresses of mail contacts
- List group mailboxes and their email addresses
- Export dynamic distribution group email address
Get All Email Address in Office 365:
To view all the Primary email addresses and alias used in your organization, run the script as follows.
Find User Mailboxes and Their SMTP Address:
User mailboxes are associated with people. To view all the user mailboxes and their primary and proxy addresses, you can run the script with –UserMailboxOnly Param.
Export Shared Mailboxes’ Email Addresses
A shared mailbox is a kind of user mailbox that doesn’t have a user name and password. Based on the permission given, users can access the shared mailbox. To find shared mailbox alias, run the script with –SharedMailboxOnly parameter.
View Distribution Lists and Their Email Addresses:
Distribution lists are used to send emails and notifications to groups of people for communication and collaboration purposes. You can list all the distribution groups and their SMTP and alias addresses by using the format below.
Find Guest Users’ Email Addresses:
In the Office 365 environment, guest users can be added through Azure Active Directory, SharePoint, Microsoft Teams, etc. To list all the guest users and the associated email addresses, execute the script with –GuestOnly param as shown below.
List Mail Contacts and Their Email Address:
Mail contacts are for people who exist outside your organization. Each mail contact has an external email address. To get a list of mail contacts with their external email address, run as follows.
View Email Address of the Group Mailboxes:
Group mailboxes are Microsoft 365 groups that are used for collaboration with both internal and external users. It includes services like SharePoint, Teams, Planner, etc. To get all the Office 365 groups and their email alias, you can execute the script with –GroupMailboxOnly param.
Get Dynamic Distribution Group Email Addresses:
Dynamic distribution groups are mail-enabled groups that send mass emails based on their dynamic membership. The group membership is determined by the AD property that matches the group condition. To view dynamic distribution groups’ email addresses, run the script as shown below.
I hope this blog will help you get all Office 365 email addresses, and you can change the email address if required. Also, you can add or remove alias based on the business needs.