Hi,
Please check to see if this works.
foreach ($Mailbox in $Mailboxes) {
$Mailbox.EmailAddresses | Where-Object { $_.AddressString -like "*@xyz.com" } | ForEach-Object {
# Remove the -WhatIf parameter after you tested and are sure to remove the secondary email addresses
Set-Mailbox $Mailbox.Name -EmailAddresses @{remove = $_ } -WhatIf
# Write output
Write-Host "Removing $_ from $Mailbox Mailbox" -ForegroundColor Green
}
}
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.