Exchange 2010 powershell problem deleting secondary email address

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.
Mark LewisAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Todd NelsonSystems EngineerCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
systechadminConsultantCommented:
Can you try to  restart the Transport service or Restart the server and see if the secondary email is gone.
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.