Export Office 365 Email Addresses to CSV using Powershell

In this post, I am going write steps to export the list of exchange online users and their email addresses from Office 365 to csv file. We can use the powershell cmdlet Get-Mailbox to get mailbox information and use the cmdlet Export-CSV to export content to csv file.

Note: Before proceed, Connect Exchange Online Remote PowerShell.

Then run the below powershell command to list the mailbox users and its primary email address.

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,PrimarySmtpAddress

The following command export all the exchange online users and its associated email addresses to csv file.

Get-Mailbox -ResultSize Unlimited |
Select-Object DisplayName,PrimarySmtpAddress, @{n="EmailAddresses";e={$_.EmailAddresses |
Where-Object {$_ -like "smtp*"} | ForEach-Object {$_.Substring(5)}}} | 
Export-Csv "C:\o365-email-addresses.csv" -NoTypeInformation -Encoding UTF8
Advertisement

4 thoughts on “Export Office 365 Email Addresses to CSV using Powershell”

  1. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free.

    Reply
  2. This was very helpful and worked perfect, but can you explain the use of “ForEach-Object {$_.Substring(5)}” in this. Thanks for providing help.

    Reply
    • The email addresses are populated with the prefix text “SMTP:” (For Primary SMTP Address) and “smtp:” (For Secondary or Proxy SMTP Addresses). So we are using the command “ForEach-Object {$_.Substring(5)}” to remove the first 5 chars from all the email addresses.

      Reply

Leave a Comment