Tuesday, May 01, 2018

How to Change the Domain of an Office 365 Group

It's not an unfamiliar scenario with all of the rebranding that's happening these days. Your Office365 group has the wrong mail domain and now you want to change it.

It's the kind of thing that you'd expect to be able to change via the admin portal. After all, there's a neat little domain selector box on the page.

Alas, that's not how Office 365 groups work.

You need PowerShell for that one.

PowerShell to the Rescue

PowerShell, the interface you have when you don't have an interface... 

Here's how to change the domain on your group.

Run PowerShell as an Administrator and type the following commands;


  1. Set-ExecutionPolicy RemoteSigned
  2. $UserCredential = Get-Credential
  3. $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
  4. Set-UnifiedGroup -Identity "Group English Name" -PrimarySmtpAddress "GroupNewEmailAddress"

    Where Group English Name is the English Name of the Group (ie: not the email address
    and
    GroupNewEmailAddress is the new email address that you want the group to have
  5. Remove-PSSession $Session
  6. Exit


A Walkthrough

The commands that you are expected to type appear below in boldface;

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y

PS C:\WINDOWS\system32> $UserCredential = Get-Credential

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential

PS C:\WINDOWS\system32> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection


PS C:\WINDOWS\system32> Import-PSSession $Session

WARNING: The names of some imported commands from the module 'tmp_vwnpqgxq.qak' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0        tmp_vwnpqgxq.qak                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember...


PS C:\WINDOWS\system32> Set-UnifiedGroup -Identity "All Staff" -PrimarySmtpAddress "AllStaff@newdomain.com"

PS C:\WINDOWS\system32> Remove-PSSession $Session

PS C:\WINDOWS\system32> Exit

No comments: