Get All Office 365 Email Addresses

Why would this be helpful?

If you have a tenancy where mail has always existed in Office365 and they now want to implement Directory Synchronization you will need to extract all user email addresses (proxy addresses) in order to import them into on-premises AD.

Failure to update AD objects prior to Initial Sync will result in AD overwriting the user’s alias’s in Office 365.

 

1) Connect to Office 365 Tenancy

$Usercredential = Get-Credential [email protected]
Connect-MSOLService -Credential $Usercredential

 

2) Get all user email addresses

Get-Mailbox | FT -Wrap Name, DisplayName,PrimarySmtpAddress,EmailAddresses

 

3) Get all user email addresses to .csv

Get-Mailbox -ResultSize Unlimited | Where {$_.name -NotLike ‘*DiscoverySearchMailbox*’} | Sort Alias | Select UserPrincipalName, DisplayName,Name, Alias,RecipientTypeDetails, EmailAddresses, PrimarySmtpAddress, MicrosoftOnlineServicesID, WindowsLiveID, WindowsEmailAddress | Export-CSV  c:\O365Info\GetMailbox.csv –NoTypeInformation