How to change a Team email

There are a lot of reasons that can lead you to a rename of a Team, either because the self-creation is enabled, and the names don’t follow the internal rules or simply because the name no longer makes sense.

On Microsoft Teams you have a graphical interface that will allow you to change the name and the description of the Team however the email will not change to reflect the modification.

To modify the email, you will need to use the Exchange PowerShell below to create a new alias and delete the old one.

  1. Copy the code paste it on notepad and modify the variables to match your environment
  2. #Adjust variables 
    $originalEmail = "formula1"
    $newEmail = "formula1-2019"
    $domain = "contoso.com"
    $office365domain = "contoso.onmicrosoft.com"
    $groupName = "Formula 1 2019"
    $removeOldEmail = $false
    
    #Login
    $UserCredential = Get-Credential
    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
    Import-PSSession $Session -DisableNameChecking
    
    #SMTP Domain 
    Set-UnifiedGroup -Identity $groupName -EmailAddresses: @{Add =("{0}@{1}" -f $newEmail, $domain)}
    Set-UnifiedGroup -Identity $groupName -PrimarySmtpAddress ("{0}@{1}" -f $newEmail, $domain)
    
    
    #Office 365 Domain 
    Set-UnifiedGroup -Identity $groupName -EmailAddresses: @{Add =("{0}@{1}" -f $newEmail, $office365domain)}
    Set-UnifiedGroup -Identity $groupName -PrimarySmtpAddress ("{0}@{1}" -f $newEmail, $office365domain)
    
    
    #Remove the old email 
    if ($removeOldEmail){
    	Set-UnifiedGroup -Identity $groupName -EmailAddresses: @{Remove=("{0}@{1}" -f $originalEmail, $domain)}
    	Set-UnifiedGroup -Identity $groupName -EmailAddresses: @{Remove=("{0}@{1}" -f $originalEmail, $office365domain)}
    }
    
    Remove-PSSession $Session
    
  3. Save the file with the name changeMail.ps1
  4. Right click on the file and select run with PowerShell
  5. If asked type Y on the execution policy
  6. Enter your credentials and wait for the execution of the file

Be careful when using this script, make sure you will not cause any disruption on your teams.

Business vector created by rawpixel.com – www.freepik.com


No comments yet

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: