How to list or export all Mailbox Email Addresses in Exchange 2007/2010 using PowerShell
This one comes up quite often, so I figured I’d make a quick and easy script for it. The first step is to make sure you’re on a machine with the Exchange Management Tools installed, and logged on as a user with privileges to read mailbox properties. If you don’t want to read the explanation, skip ahead to The Script. First, let’s create an empty array to store the results in:
Next, we’ll grab all the mailboxes from the organisation. By default Exchange will only return the first 1000 results, so we need to specify the
ResultSize parameter to ensure all mailboxes are counted.
Now loop through each mailbox using a
Per each mailbox, let’s loop through the email addresses. Exchange stores SMTP, X400, SIP and any number of other address types in this property. We’re only interested in SMTP addresses, so we’ll use an if statement inside this loop. Because Exchange may qualify the address with either
smtp: we’ll convert the prefix to lower and then do the compare:
Doing this has allowed us to only inspect SMTP addresses. Now we can create an object and insert the appropriate variables in it. Finally, we’ll append it to the
$addresses array we created earlier. We’ll use SubString to retrieve only characters after the 5th position from the email address (
smtp:firstname.lastname@example.org will become
Now we have an object,
$addresses which we can export and/or format in any number of ways. In my example below, I have exported it to CSV then opened the CSV (using
Invoke-Item) with its default handler. You could also use Format-Table, Format-List and any number of different methods. You can even interact with this array in other cmdlets or pass it down the pipeline. The possibilities are endless!