How To Remove A Specific Domain From All Exchange 2013 /2010 Mailboxes

The code below will show you how to remove a specific domain from all users mailboxes.

The code was tested on Exchange 2010 and Exchange 2013.

#REMOVE_DOMAIN.PS1

if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue) -eq $null )

{

add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010

}

foreach($i in Get-Mailbox -ResultSize Unlimited) {

$i.EmailAddresses |

?{$_.AddressString -like ‘*@ntweekly.com’} | %{

Set-Mailbox $i -EmailAddresses @{remove=$_}

}

}

 


Posted

in

,

by