Export Email Addresses in Exchange 2013

For a project I had to create a CSV file with all Mailboxes, their UPN and their Email addresses. Not a big deal since you can use the following command:

Get-Mailbox | Select UserPrincipalName,EmailAddresses

image

Exporting to a CSV is a default feature in PowerShell using the Export-Csv command, like this:

Get-Mailbox | Select UserPrincipalName,EmailAddresses | Export-Csv C:\Temp\Addresses.csv

Unfortunately this does not give the desired outcome. Since the EmailAddresses property is a multi-value property only the definition is exported and not the values and it will show up like this:

#TYPE Selected.Microsoft.Exchange.Data.Directory.Management.Mailbox
“UserPrincipalName”,”EmailAddresses”
“Michael@azurelabs.nl”,”Microsoft.Exchange.Data.ProxyAddressCollection”

image

This can be solved by creating a custom field and grab all values of the property, joined with a “,” character, like this:

Get-Mailbox | Select UserPrincipalName, @{Name='EmailAddresses'; Expression={$_.EmailAddresses -join ","}}

image

Combine this with the Export-Csv command:

Get-Mailbox | Select UserPrincipalName, @{Name='EmailAddresses'; Expression={$_.EmailAddresses -join ","}} | Export-Csv C:\Temp\Addresses.csv

And this will result in a proper CSV file:

image

Special thanks to Michel de Rooij, my living PowerShell repository.

One thought on “Export Email Addresses in Exchange 2013”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s