PowerShell script to change PrimarySMTPAddress of Office 365 Distribution Group

# run the PowerShell ISE as Administrator

Import-Module Azure

Set-ExecutionPolicy RemoteSigned

$UserCredential = Get-Credential

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

Import-PSSession $Session

# This example makes the following changes to the existing Office 365 Group named testgroup4
# The primary email address is changed to testgroup4@company7623.contoso.pfelabs.ms
# The Office 365 Group is allowed to receive mail from unauthenticated (external) senders

Set-UnifiedGroup -Identity "testgroup4" -PrimarySmtpAddress testgroup4@company7623.contoso.pfelabs.ms -RequireSenderAuthenticationEnabled $false

Get-UnifiedGroup 'testgroup4' | select-object name, EmailAddresses, PrimarySmtpAddress

# Name EmailAddresses PrimarySmtpAddress
# —- ————– ——————
# testgroup4 {smtp:testgroup4@company7623contoso.onmicrosoft.com, SMTP:testgroup4@company7623.contoso.pfelabs.ms} testgroup4@company7623.contoso.pfelabs.ms

Remove-PSSession $Session

Comments (0)

Skip to main content