<

Appending to a list of proxyAddresses in Exchange Management Shell

Published on
6,063 Points
3,063 Views
Last Modified:
Jason Crawford
BRONZE EXPERT
(FYDIBOHF24SPDLT)
Utilizing an array to gracefully append to a list of EmailAddresses
Adding to a list of EmailAddresses in Exchange has the potential to be one of those 'gotcha' issues that, if performed incorrectly, can really make you momentarily rethink your career in IT.  This is because if proper measures are not taken, the list of mailbox alias' can be overwritten by your one addition.  For example, if the following command was run, all pre-existing proxyAddresses would be overwritten with the addition of userA1@domain.com:
 
Set-Mailbox userA -EmailAddresses 'userA1@domain.com'

Open in new window


The process to work around this has traditionally involved adding the complete list of alias' each time instead of just the one like so:
 
$user = Get-Mailbox userA
$user.EmailAddresses += 'userA1@domain.com'
$user | Set-Mailbox

Open in new window


A simple work around available in PowerShell 2.0 and beyond involves the use of an array:
 
Set-Mailbox userA -EmailAddresses @{add='userA1@domain.com'}

Open in new window


Now we can add just one address at a time instead of being forced to account for the entire list with each new request.  Enjoy!
0
Ask questions about what you read
If you have a question about something within an article, you can receive help directly from the article author. Experts Exchange article authors are available to answer questions and further the discussion.
Get 7 days free