Created
May 12, 2021 17:23
-
-
Save matsimon/047e703af95e4158356142e817157083 to your computer and use it in GitHub Desktop.
A Powershell-Script that changes existing Teams/Unified Groups primary Mail address since Exchange Online Adress policies only apply to new groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Connect-ExchangeOnline | |
| "DisplayName,Modified,Primary,Leftovers" | Out-File -FilePath modifications.txt | |
| $UnifiedGroups = Get-UnifiedGroup -ResultSize unlimited | |
| foreach ($Group in $UnifiedGroups) { | |
| $modified = $false | |
| foreach ($address in $Group.EmailAddresses){ | |
| if ($address -match "@oldprimarydomain.tld"){ | |
| # primaryAddress has not "SMTP:" | |
| $updatedAdress = $address -replace "@oldprimarydomain.tld","@groups.oldprimarydomain.tld" | |
| $primaryAddress = $updatedAdress -replace "SMTP:","" | |
| # Define new primary address, then remove old one | |
| $modified = $true | |
| Set-UnifiedGroup -Identity $Group.Name -PrimarySmtpAddress $primaryAddress | |
| Set-UnifiedGroup -Identity $Group.Name -EmailAddresses @{remove=$address} | |
| } | |
| } | |
| $updatedGroup = Get-UnifiedGroup -Identity $Group.Name | |
| $leftovers = $false | |
| foreach ($address in $updatedGroup.EmailAddresses){ | |
| if ($address -match "@oldprimarydomain.tld"){ | |
| $leftovers = $true | |
| } | |
| } | |
| $a = -join($updatedGroup.DisplayName,";",$modified,";",$updatedGroup.PrimarySmtpAddress,";",$leftovers) | |
| Write-Host $a | |
| $a | Out-File -Append -FilePath modifications.txt | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment