Exchange 2010 powershell problem deleting secondary email address

Mark Lewis
Mark Lewis used Ask the Experts™
on
We are letting our secondary email address go (old name). I deleted the domain from the policy and accepted domain in Exchange but it left all the old email addresses on the recipients. I really need to know how to remove them form 200+ users in one swoop but decided to test on a single user first.

I ran this command: Set-Mailbox "John Doe" -EmailAddresses @{remove="jdoe@mydomain.com"}

I got this in return: WARNING: The command completed successfully but no settings of 'mydoamin.com/.../John Doe' have been modified.

Obviously the secondary email address was not removed.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Systems Engineer
Top Expert 2016
Commented:
Try the following script.  Run it in the Exchange Management Shell.  You will need to update the $OUScope variable and "*@d2.local" for your organization.  It will recurse through your AD and remove any proxyAddresses with the specific domain name.

$OUScope = "DC=d2,DC=local"
$N = 0
Write-Host "Searching mailboxes in $OUScope...."
foreach ($Tmailbox in Get-Mailbox -OrganizationalUnit $OUScope -ResultSize Unlimited) 
{
     $Tmailbox.EmailAddresses | ?{$_.AddressString -like '*@d2.local'} | %{
     Set-Mailbox $Tmailbox -EmailAddresses @{remove=$_}
     Write-host "Removing $_ from $Tmailbox Mailbox"
     $N++
     }
}

Open in new window

Gaurav SinghSolutions Architect

Commented:
Can you try to  restart the Transport service or Restart the server and see if the secondary email is gone.
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015
Commented:
Check the exact email address you wanted to remove. The code shown above will of course take care of that for all users found; your issue with the test case should be solved if you replace Get-Mailbox -OrganizationalUnit $OUScope -ResultSize Unlimited with Get-Mailbox "John Doe" in #a42061724 ( $OUScope doesn't play any role here then, of course). And you can remove the occurences of $N, if you do not need a variable counting the removals made.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial