Add email addresses to users when a new domain is added

Whenever you connect you a domain to Office 365, new users will get the email addresses derived from the new domain, but existing users do not.

The next script adds 2 email addresses to existing users. E.g. when you add contoso.com it will add firstname.name@contoso.com and alias@contoso.com to the existing users.

$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange –ConnectionUri 
https://ps.outlook.com/powershell/ -Credential $LiveCred 
     -Authentication Basic -AllowRedirection
Set-ExecutionPolicy RemoteSigned
Import-PSSession $Session
$users = Get-Mailbox
foreach ($a in $users) 
{
   $a.emailaddresses.Add("$($a.alias)@newdomain.com")
   $myEmail = $a.firstname + $a.lastname
   $myEmail = $myEmail.replace(' ','') 
   $a.emailaddresses.Add("$myEmail@newdomain.com")
} 

$users | %{Set-Mailbox $_.Identity -EmailAddresses $_.EmailAddresses}
Advertisements

Leave a Reply