Managing email addresses in Exchange 2010
In this post I wrote about a way to modify email addresses with the Update-List cmdlet in a Exchange 2007 environment. Exchange 2010 has been released in the meantime and this method no longer works, you'll get this warning:
[PS] > Get-Mailbox User1 | Update-List -Property EmailAddresses -Add TestUser1@domain.com | Set-Mailbox
WARNING: The command completed successfully but no settings of 'domain.com/Users/TestUser1' have been modified.
Exchange 2010 uses PowerShell 2.0 Remote PowerShell sessions to manage Exchange and that changed the way objects and parameters are bind in the implementation of remote Exchange commands.
In 2010 we can use a hash table to modify the EmailAddresses property. For example, to add new SMTP address we use the 'Add' keyword:
[PS] > Set-Mailbox User1 -EmailAddresses @{Add='TestUser1@domain.com’}
The 'Add' keyword can be replaced with the '+' shortcut:
[PS] > Set-Mailbox User1 -EmailAddresses @{'+'='TestUser1@domain.com’}
To remove addresses use the 'Remove' keyword, or its '-' alias.
[PS] > Set-Mailbox User1 -EmailAddresses @{Remove='TestUser1@domain.com’}
[PS] > Set-Mailbox User1 -EmailAddresses @{'-'='TestUser1@domain.com’}
Note that if you decide to use the +/- aliases then you need to enclose them in quotes otherwise PowerShell will interpret them as the '-='/'+=' PowerShell operators.
We can also add and remove addresses in one call:
[PS] > Set-Mailbox User1 -EmailAddresses @{'Add'=@('TestUser20@domain.com','TestUser21@domain.com'); Remove='TestUser1@domain.com'}
Now, the EmailAddresses parameter is just one example, in fact you can use this method to modify any other MultiValuedProperty parameter:
[PS] > Set-RecipientFilterConfig -BlockedRecipients @{Add=@('user1@domain.com','user2@domain.com')}
[PS] > Set-TransportConfig -GenerateCopyOfDSNFor @{Add=@('5.4.7', '5.7.1');Remove= '5.7.2'}
[PS] > Get-Mailbox User2 | Set-Mailbox -RejectMessagesFrom @{Add='administrator@contoso.com'; Remove='sysadmin@contoso.com'}
[PS] > Get-Mailbox User2 | Set-Mailbox -GrantSendOnBehalfTo @{Add=('administrator@contoso.com','sysadmin@contoso.com')}
Have fun.