Post date: Sep 15, 2015 10:36:53 AM
Replace @contoso.com in the script below with the domain name you want to remove
Save as filename.ps1
In EMS, browse to the folder when the script is located and type ./filename.ps1
foreach($i in Get-Mailbox -ResultSize Unlimited) { $i.EmailAddresses | ?{$_.AddressString -like '*@contoso.com'} | %{ Set-Mailbox $i -EmailAddresses @{remove=$_} } }
This will simply iterate over each mailbox, and look for any address using @contoso.com. Any matches are removed. To use this code, just replace contoso.com with whatever e-mail domain you want to target.
In this example, we’re using Get-Mailbox to first retrieve all of the mailboxes. If you need to remove these address from groups, replace “Get-Mailbox” and “Set-Mailbox” with “Get-DistributionGroup” and “Set-DistributionGroup”. This goes for other recipient types as well, such as dynamic distribution groups and mail users, etc.