We can use the Exchange Powershell command Get-Mailbox to retrieve the primary email address and secondary (or alias) email addresses for all mailboxes (ex: UserMailbox, SharedMailbox, etc..). We can also use the Get-Recipient cmdlet to get email addresses for all mail-enabled objects (for example, mailboxes, mail users, mail contacts, unified groups, and distribution groups). In this post, I am going to explain export office 365 users email addresses using powershell.
Run the below command to export the primary and alias email addresses for all user mailboxes.
1
2
3
|
Get-Mailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name= "AliasSmtpAddresses" ;Expression={( $_ .EmailAddresses | Where-Object { $_ -clike "smtp:*" } | ForEach-Object { $_ -replace "smtp:" ," "}) -join " , " }} | Export-Csv " C:\Email-Addresses.csv" -NoTypeInformation -Encoding UTF8 |
The above command exports only user mailboxes and shared user mailboxes, if you want to export email address all mail-enabled objects, then we need to use Get-Recipient cmdlet.
1
2
3
|
Get-Recipient -ResultSize Unlimited | Select-Object DisplayName,RecipientType, PrimarySmtpAddress, @{Name= "AliasSmtpAddresses" ;Expression={( $_ .EmailAddresses | Where-Object { $_ -clike "smtp:*" } | ForEach-Object { $_ -replace "smtp:" ," "}) -join " , " }} | Export-Csv " C:\Email-Addresses.csv" -NoTypeInformation -Encoding UTF8 |
If you use Exchange Online PowerShell V2 module, then you can use new equivalent commands Get-EXOMailbox and Get-EXORecipient.
1
2
3
|
Get-EXOMailbox -ResultSize Unlimited | Select-Object DisplayName,PrimarySmtpAddress, @{Name= "AliasSmtpAddresses" ;Expression={( $_ .EmailAddresses | Where-Object { $_ -clike "smtp:*" } | ForEach-Object { $_ -replace "smtp:" ," "}) -join " , " }} | Export-Csv " C:\Email-Addresses.csv" -NoTypeInformation -Encoding UTF8 |