Hybid Exchange – Bulk Email Domain Name Change

Connecting to Office 365

Next you need to connect to the O365 cloud – you only need to do this once per session (i.e. as long as you don’t close the EMS Powershell window). You will need and administrator account for the O365 environment (or tenant admin in a multi tenant environment).

NOTE: During the changes below users may not be able to log in to their O365 webmail until all changes are complete and synchronised.

 

 Connect to MSOL
Connect-msolservice

 

If you are in a multi tenant environment (i.e. you provide O365 to a number of different customers) do the following to put the tenant guid into a variable. If you only have the one O365 domain you can skip this command but you will need to remove the “-TenantId $tenid” from any of the commands below. Remember to change bobbitco.onmicrosoft.com to your O365 routing domain (hint look in your rollback.csv).

$tenid = (Get-MsolPartnerContract -domain bobbitco.onmicrosoft.com).tenantid.guid

 

Check accounts’ last dirsync time

One thing I like to check is the last time the user account did a sync to the O365 cloud this can then be compared to the same command later to check synchronisation has been completed. It’s also another check that the user details are good:

$users | foreach-object {get-msoluser -TenantId $tenid -UserPrincipalName "$($_.primarysmtpaddress)" | select userprincipalname, lastdirsynctime }

 

If you are doing lots of users you may want to pipe the above command output into to a file:

$users | foreach-object {get-msoluser -TenantId $tenid -UserPrincipalName "$($_.primarysmtpaddress)" | select userprincipalname, lastdirsynctime } | out-file c:\tmp\lastsync.txt

 

 

Check Remote Mailboxes exist (am I making you paranoid yet?)

I like to check the mailboxes exist again (this will check errors haven’t been introduced in the new .CSV):

$users | ForEach-object { $exist = [bool](Get-remotemailbox $_.primarysmtpaddress -erroraction SilentlyContinue); Write-host "$Exist, $($_. Displayname)" }

 

On the next page we’ll actually begin to make the changes!

 

2 thoughts on “Hybid Exchange – Bulk Email Domain Name Change

  1. Nice work Bobb. Two lines of your code seem to be identical though.
    “Add additional SMTP address” and “Set Primary SMTP address and disable email address policy”.

Leave a Reply