Skip to main content

Export email addresses via Exchange Powershell

·298 words·2 mins
system-administration tech exchange exchange-2007 exchange-2010 powershell sysadmin technology
James Pettigrove
Author
James Pettigrove
Cloud Engineer with a focus on Microsoft Azure
Table of Contents

The other week I had a request for a list of all email addresses of staff for use with a legacy VOIP system. Seems simple enough right but in Exchange 2007 (possibly 2010 as well) there is no option via the GUI to pump out all the email addresses from your Exchange server.

Where there is a problem, we shall find a solution right?

After a bit of Google-fu & testing, I give you a script to output all SMTP addresses to an Excel document

Requirements
#

  • Exchange Powershell (tested 2007, should work on 2010)

Steps
#

Get-Mailbox -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=EmailAddresses;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq smtp} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv c:\mailbox_alias.csv

If we examine the code above you can see that this will export all SMTP address to a CSV formatted file named mailbox_alias.csv in the root of c:\ (make sure you have the rights to write there or change the path to somewhere you do have rights). This CSV file will have columns in the following layout:

DisplayName  ServerName PrimarySMTPAddress EmailAddresses

The important thing to note is the final column EmailAddresses will provide any secondary/added SMTP address for those you use more than one email address.

In my specific case I needed to get email addresses from one specific mailbox database (staff and students are on seperate databases to make it easier to apply mailbox limits) and thus the script is a little different:

Get-Mailbox -Database "Mailserver\Databasename" -ResultSize Unlimited |Select-Object DisplayName,ServerName,PrimarySmtpAddress, @{Name=EmailAddresses;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq smtp} | ForEach-Object {$_.SmtpAddress}}} | Export-Csv c:\mailbox_alias.csv

You will note the addition of -Database "Mailserver\DatabaseName" to the script which allows you to choose a specific mailbox database to pull email addresses from.

So, there you have it; all your email addresses outputted to a nicely formatted CSV file. Too easy!

Related

Bulk creation of Active Directory User accounts via Powershell v2
·378 words·2 mins
system-administration tech active-directory powershell sysadmin technology
Most system administrators that I know has the burden (or the joy if you like a challenge) of creating and managing large quantities of users in Active Directory.
Removing a printer while the print spooler is not running
·320 words·2 mins
system-administration tech printers sysadmin technology
Many sysadmins have probably encountered a situation where due to a nasty print driver (& associated printer) the Print Spooler service stops and upon starting it up again manually decides to stop again.
Girls' Generation debut on American TV
·431 words·3 mins
k-pop girls-generation k-pop korea korean-pop snsd
For many fans of Girls’ Generation (often referred by SNSD or SoShi, both come from their Korean name) today has been a long time coming.