Answered by:
Removing legacy SMTP domains

Question
-
I am trying to remove legacy SMTP domains that are associated to my user mailboxes.
Most users have a domain1.com, domain2.com and domain3.com email address associated and due to consolidation we have stopped using domain1.com and domain2.com and we are ready to remove those and only keep domain3.com. New mailboxes are only assigned domain3.com email address but the majority of users are legacy and have these old domains.
Any idea on the powershell required to remove all domain1.com and domain2.com?
- Edited by Pegoto Friday, September 14, 2012 5:55 PM
Friday, September 14, 2012 5:54 PM
Answers
-
On Fri, 14 Sep 2012 17:54:39 +0000, Pegoto wrote:>I am trying to remove legacy SMTP domains that are associated to my user mailboxes.>>Most users have a domain1.com, domain2.com and domain3.com email address associated and due to consolidation we have stopped using domain1.com and domain2.com and we are ready to remove those and only keep domain3.com. New mailboxes are only assigned domain3.com email address but the majority of users are legacy and have these old domains.>>Any idea on the powershell required to remove all domain1.com and domain2.com?What release of Exchange?If it's 2010, try this:http://www.mikepfeiffer.net/2012/02/how-to-remove-e-mail-addresses-for-a-specific-domain-from-exchange/---Rich MatheisenMCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP- Marked as answer by Pegoto Wednesday, September 19, 2012 8:40 PM
Saturday, September 15, 2012 2:29 AM
All replies
-
Try my script from Technet galery - http://gallery.technet.microsoft.com/Remove-Oldaliasesps1-f5abf5ab
Regards, Konrad Sagala, MCT, MCSE+M, MCITP: Exchange 2007/2010, Lync 2010, Office365, Windows 2008, Virtualization
Friday, September 14, 2012 6:12 PM -
I am trying to get the script to work but it runs and ends and nothing was changed.
This is what I have in the script:
$ConfirmPreference="None" $i = 0 get-mailbox -resultsize unlimited | ForEach-Object { $maile = $_ for ($i=0; $i -lt $_.emailaddresses.count; $i++) { if ($_.emailaddresses[$i] -like "smtp:*@domain1.com") { $badaddress = $_.emailaddresses[$i] $maile.emailaddresses -= $badaddress $maile | Set-Mailbox -EmailAddresses $maile.emailaddresses } } }
The above gives an error about consecutive pipeline commands but if you remove the *@ in the -like statement then it runs but with nothing happening.
- Edited by Pegoto Friday, September 14, 2012 8:07 PM
Friday, September 14, 2012 8:05 PM -
On Fri, 14 Sep 2012 17:54:39 +0000, Pegoto wrote:>I am trying to remove legacy SMTP domains that are associated to my user mailboxes.>>Most users have a domain1.com, domain2.com and domain3.com email address associated and due to consolidation we have stopped using domain1.com and domain2.com and we are ready to remove those and only keep domain3.com. New mailboxes are only assigned domain3.com email address but the majority of users are legacy and have these old domains.>>Any idea on the powershell required to remove all domain1.com and domain2.com?What release of Exchange?If it's 2010, try this:http://www.mikepfeiffer.net/2012/02/how-to-remove-e-mail-addresses-for-a-specific-domain-from-exchange/---Rich MatheisenMCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP- Marked as answer by Pegoto Wednesday, September 19, 2012 8:40 PM
Saturday, September 15, 2012 2:29 AM -
Hi
What about below script:-
Get all mailboxes into an Array $mbxs = @(get-mailbox -Resultsize Unlimited) #Iterate through each mailbox foreach ($mbx in $mbxs) { #Create two copies of the email addresses in the returned mailbox $CurrentList = $mbx.emailaddresses #the second copy is the one where the changes will take place. $NewList = $mbx.emailaddresses #Iterate through each address in the address list. foreach ($Address in $CurrentList) { #see if the current address matches the domain you are wanting to remove if ($Address.tostring() -match "OLDDOMAIN.com") { #If the match is found, remove that address from the list. $NewList -= $Address } } #Overwrite the old list with the new list. set-mailbox $mbx -emailaddresses $NewList
connect me :-
http://in.linkedin.com/in/satya11
http://facebook.com/satya.1000
Don't forget to mark helpful or answer
Saturday, September 15, 2012 5:54 AM -
Hi
The above Script is good, but I suggest to add on more condition in the Comparing Part becasue Pegoto said he would like to move two domain
if ($Address.tostring() -match "OLDDOMAIN01.com" -Or "OLDDOMAIN02.com")
Also I think he missed a closing bracket "}" in the end.
Cheers
Zi Feng
TechNet Community Support
- Edited by Zi FengModerator Monday, September 17, 2012 8:12 AM
Monday, September 17, 2012 8:11 AMModerator -
Change get-mailbox -resultsize unlimited |ForEach-Object { to $mailboxlist = get-mailbox -resultsize unlimited $mailboxlist | ForEach-Object {
For some reason in Exchange 2010 sometiimes it works better (script was prepared for Exchange 2007)
Regards, Konrad Sagala, MCT, MCSE+M, MCITP: Exchange 2007/2010, Lync 2010, Office365, Windows 2008, Virtualization
Monday, September 17, 2012 10:15 AM -
Thanks, this worked perfectly and it is Exchange 2010.Wednesday, September 19, 2012 8:41 PM