In my last Exchange PowerShell post i looked at listing users hidden from the Global Address List. In this post we’ll look at listing all email addresses in use in Microsoft Exchange. This can be useful if you are trying to add an email address and you get an error message because it is already in use somewhere.
Although email addresses are most often associated with mailboxes, they can be found in other items too. In Exchange, Contacts and Distribution lists also have email addresses (as do Public Folders which we’ll look at another time). For that reason we can’t use Get-Mailbox which we used in the last post as that will limit our search to mailboxes only, instead we’ll be using Get-Recipient.
If you pipe Get-Recipient into Get-Member you will see an EmailAddresses property which is exactly what we are after. As you can see below GM is an alias of Get-Member.
The command is:
Get-Recipient | GM
Based on what we learnt in the last post we can start off with the command:
Get-Recipient | Select Name, EmailAddresses
In the image below I have compared the output of Get-Recipient with Get-Mailbox so that you can see Get-Recipient is returning more information.
You’ll also note that some of the mailboxes appear to have more than one email address, now how will we expand the property to see them all?
The Select command is very powerful to find out more about it run the command:
Get-Help Select -Full
If you run the command above you will see one of the parameters is -ExpandProperty, which we will use to expand the EmailAddresses property.
The command is:
Get-Recipient | Select Name -ExpandProperty EmailAddresses
Get-Recipient | Select Name -ExpandProperty EmailAddresses | Select Name, SmtpAddress
So our final command looks like this:
Get-Recipient | Select Name -ExpandProperty EmailAddresses | Select Name, SmtpAddress | Export-csv c:\temp\AllEmailAddress.csv
The PowerShell command above works on both Exchange 2007 and Exchange 2010.