Hi, @Glenn Maxwell
Based on your description, I understand that you want to do something with the distribution group.
You can use the following command to rename TestA to TestB:
Set-DistributionGroup -Identity "TestA" -DisplayName "TestB"
Then, you can use the following command to change the email address from TestA@contoso.com to TestB@contoso.com:
Set-DistributionGroup -Identity "TestB" -PrimarySmtpAddress TestB@contoso.com
After my test, after I successfully changed my email address, TestA@contoso.com automatically changed to the alias of TestB, i.e. secondary email. If you fail to convert automatically, you can also use the command:
Set-DistributionGroup -Identity "TestB@contoso.com" -EmailAddresses @{Add="TestA@contoso.com"}
After the above operations, you can use the following command to check whether the changes are completed:
Get-DistributionGroup -Identity TestB@contoso.com | Format-List Name,PrimarySmtpAddress,EmailAddresses
The operation success is shown in the following figure.
In Microsoft Exchange and Exchange Online, the secondary email address (alias) is not directly visible to the user. When a user views a distribution group on a mail client, they typically only see the primary email address. When you send a message to a secondary email address, the mail client also displays the primary email address of the distribution group.
Both the above commands can be executed in both online and on-premises.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".