We are a Microsoft partner and have been standing up a lot of clients on Office 365, the management of which requires a lot of PowerShell use to administer properly. My last boss told me that Microsoft’s move away from the GUI toward PS scripting is what is going to ‘separate the men from the boys’, and I’ve taken this to heart, trying to script out everything as much as possible. Server 2012 has really made improvements over 2008 as far as this goes, and Exchange Online and Office 365 (AKA Microsoft Online Services) are strongly there as well. Sure, there are web interfaces for them, but Microsoft seems to have a habit of changing the navigation and language every few weeks and the GUI has been inconsistent between the business and enterprise plans as well, so the Powershell commands seem be the way to go.

For this most recent job, we had a client who wanted to change domain names, so we stood up the new domain on O365 and configured client workstations for the new accounts. Once that was done we verified the old domain with Microsoft in anticipation of routing the old domain to the new mailboxes. Rather than manually add each additional SMTP address for each user account, I used the following script. Make sure you connect to Exchange Online using remote PowerShell first.

$users = get-user * #Filter your OU appropriately, this was a blanket change for a flat hierarchy.
foreach ($user in $users)
$mailbox = get-mailbox $user.identity
$newmailbox = $user.id + "@yourNewDomain.com"
set-mailbox -identity $user.identity -EmailAddresses @{Add=$newmailbox}

You can then verify that the changes went correctly with the following:

foreach ($user in $users) {
$mailbox = get-mailbox $user.identity
write-host  $addresses