Powershell Script to Remove Invalid SMTP Addresses
We are currenly in Migration from Notes to Exchange 2010. We are using the Quest Migration tools for the process and it has been going well. However there is a By-Product of using the Tool, which is an Invalid SMTP Domain.
Users who are moved with the tool get the following SMTP Address added to their Exchange account:
username@domain.com@Notes Domain
This causes an issue with ActiveSync setups and other things. I found the following script:
$mailbox = Get-Mailbox$mailbox | foreach { for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--) { $address = $_.EmailAddresses[$i] if ($address.SmtpAddress -like "*@baddomain.com" ) { Write-host("Remove smtp adress: " + $address.AddressString.ToString() ) $_.EmailAddresses.RemoveAt($i) } }$_|set-mailbox -EmailAddresses $_.EmailAddresses}
However even it chokes at the address with two '@' symbols in the middle.
Can anyone think up a script to help remove this? The vendor's stance is that they don't assist with 'Exchange Issues'.
February 10th, 2012 11:16am
This is probably unsupported but you can look the proxyaddresses attribute on recipients and remove the problematic row.
How many isers are we talking about here?
lasse at humandata dot se, http://anewmessagehasarrived.blogspot.com
Free Windows Admin Tool Kit Click here and download it now
February 10th, 2012 4:34pm
On Fri, 10 Feb 2012 16:07:38 +0000, John Owens - BDC wrote:
>
>
>We are currenly in Migration from Notes to Exchange 2010. We are using the Quest Migration tools for the process and it has been going well. However there is a By-Product of using the Tool, which is an Invalid SMTP Domain.
>
>
>
>Users who are moved with the tool get the following SMTP Address added to their Exchange account:
>
>
>
>username@domain.com@Notes Domain
>
>This causes an issue with ActiveSync setups and other things. I found the following script: $mailbox = Get-Mailbox$mailbox | foreach { for ($i=$_.EmailAddresses.Count;$i -ge 0; $i--) { $address = $_.EmailAddresses[$i] if ($address.SmtpAddress -like "*@baddomain.com"
) { Write-host("Remove smtp adress: " + $address.AddressString.ToString() ) $_.EmailAddresses.RemoveAt($i) } }$_|set-mailbox -EmailAddresses $_.EmailAddresses}
>
>However even it chokes at the address with two '@' symbols in the middle.
Chokes how?
Have you looked at admodify?
http://technet.microsoft.com/en-us/library/aa996216(EXCHG.65).aspx
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
February 10th, 2012 10:50pm
Hi John,
Could you use this command to output the emailaddresses for problem user that I can know how this email-address saved in the Exchange Server?
(Get-mailbox identity username).Emailaddresses
Per my knowledge, Exchange will not allow you to save email address
username@domain@note Domain as an smtp address, so I need to know how it saved in your Exchange before try to write the script for you.
Thanks,
Evan Liu
TechNet Subscriber Supportin forum
If you have any feedback on our support, please contact
tngfb@microsoft.com
Evan Liu
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2012 3:21am
To answer all the asked questions:
@Lasse ->> 750 Users all of them have it.
@Rich ->> I get an error stating the SMTP address is invalid and a bunch of line references.
@Evan --> It got injected into Exchange by the Migration software, probably a direct AD write. Keep in mind 750 users all have this (unless I've manually removed it).
February 13th, 2012 8:22am
This is what I get when I run the requested command. Please note the error, it also appears that my previously mentioned script isn't working (even though it says it is) because addresses are coming back as if they were in the Address Generation
Policy. There should't be any @www., @inet1., @portal, @bencocp, @powerhouse or @mailbox entries.
---
AddressString :
cstrohl@benco.com
ProxyAddressString : sip:cstrohl@benco.com
Prefix : SIP
IsPrimaryAddress : False
PrefixString : sip
ParseException : System.ArgumentOutOfRangeException: The address
'cstrohl@exchange.benco.com@Benco Dental' is not a
valid SMTP address.
at Microsoft.Exchange.Data.SmtpProxyAddress..ctor(String address, Boolean isPrimaryAddress)
at Microsoft.Exchange.Data.SmtpProxyAddressPrefix.GetProxyAddress(String address, Boolean isPri
maryAddress)
at Microsoft.Exchange.Data.ProxyAddress.Parse(String proxyAddressString, String prefixString, S
tring addressString)
AddressString :
cstrohl@exchange.benco.com@Benco Dental
ProxyAddressString : smtp:cstrohl@exchange.benco.com@Benco Dental
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin.Strohl@benco.com
AddressString :
Calvin.Strohl@benco.com
ProxyAddressString : smtp:Calvin.Strohl@benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
AddressString : /o=Benco/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=cstrohl.benco.com
ProxyAddressString : X500:/o=Benco/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Recipients/cn=cstrohl.benco.co
m
Prefix : X500
IsPrimaryAddress : True
PrefixString : X500
SmtpAddress :
Calvin_Strohl@benco.com
AddressString :
Calvin_Strohl@benco.com
ProxyAddressString : smtp:Calvin_Strohl@benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@exchange.benco.com
AddressString :
cstrohl@exchange.benco.com
ProxyAddressString : smtp:cstrohl@exchange.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@notes.benco.com
AddressString :
Calvin_Strohl@notes.benco.com
ProxyAddressString : smtp:Calvin_Strohl@notes.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@bencocp.benco.com
AddressString :
Calvin_Strohl@bencocp.benco.com
ProxyAddressString : smtp:Calvin_Strohl@bencocp.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@portal.benco.com
AddressString :
Calvin_Strohl@portal.benco.com
ProxyAddressString : smtp:Calvin_Strohl@portal.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
chs@benco.com
AddressString : chs@benco.com
ProxyAddressString : smtp:chs@benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@www.benco.com
AddressString :
cstrohl@www.benco.com
ProxyAddressString : smtp:cstrohl@www.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@mailbox.benco.com
AddressString :
cstrohl@mailbox.benco.com
ProxyAddressString : smtp:cstrohl@mailbox.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@powerhouse.benco.com
AddressString :
cstrohl@powerhouse.benco.com
ProxyAddressString : smtp:cstrohl@powerhouse.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@www.benco.com
AddressString :
Calvin_Strohl@www.benco.com
ProxyAddressString : smtp:Calvin_Strohl@www.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@mailbox.benco.com
AddressString :
Calvin_Strohl@mailbox.benco.com
ProxyAddressString : smtp:Calvin_Strohl@mailbox.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@inet1.benco.com
AddressString :
Calvin_Strohl@inet1.benco.com
ProxyAddressString : smtp:Calvin_Strohl@inet1.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@bencocp.benco.com
AddressString :
cstrohl@bencocp.benco.com
ProxyAddressString : smtp:cstrohl@bencocp.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@inet1.benco.com
AddressString :
cstrohl@inet1.benco.com
ProxyAddressString : smtp:cstrohl@inet1.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
AddressString : Calvin Strohl/Benco
Dental@BENCO DENTAL
ProxyAddressString : notes:Calvin Strohl/Benco Dental@BENCO DENTAL
Prefix : NOTES
IsPrimaryAddress : False
PrefixString : notes
SmtpAddress :
cstrohl@portal.benco.com
AddressString :
cstrohl@portal.benco.com
ProxyAddressString : smtp:cstrohl@portal.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
Calvin_Strohl@powerhouse.benco.com
AddressString :
Calvin_Strohl@powerhouse.benco.com
ProxyAddressString : smtp:Calvin_Strohl@powerhouse.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
SmtpAddress :
cstrohl@benco.com
AddressString :
cstrohl@benco.com
ProxyAddressString : SMTP:cstrohl@benco.com
Prefix : SMTP
IsPrimaryAddress : True
PrefixString : SMTP
SmtpAddress :
cstrohl@notes.benco.com
AddressString :
cstrohl@notes.benco.com
ProxyAddressString : smtp:cstrohl@notes.benco.com
Prefix : SMTP
IsPrimaryAddress : False
PrefixString : smtp
Free Windows Admin Tool Kit Click here and download it now
February 13th, 2012 12:44pm
On Mon, 13 Feb 2012 13:08:22 +0000, John Owens - BDC wrote:
>
>
>To answer all the asked questions:
>
>@Lasse ->> 750 Users all of them have it.
>
>@Rich ->> I get an error stating the SMTP address is invalid and a bunch of line references.
So ADMODIFY doesn't work?
If all else fails you can always use LDIFDE.exe to remove the problem
addresses.
dn: cn=Paula Jensen, ou=Product Development, dc=airius, dc=com
changetype: modify
delete: proxyaddresses
proxyaddresses: user@domain@domain
-
dn: cn=Joe Blow, ou=Sales, dc=airius, dc=com
changetype: modify
delete: proxyaddresses
proxyaddresses: user2@domain@domain
-
etc.
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
February 13th, 2012 8:11pm
You can use this to have a try:
$mailboxes=get-mailbox -resultsize unlimited
foreach($mailbox in $mailboxes)
{
for($i=($mailbox.EmailAddresses.count)-1; $i -ge 0; $i--)
{
$address=$mailbox.EmailAddresses[$i]
$addressString=$address.addressString
if($addressString -like "*@*@*")
{
$mailbox.EmailAddresses.removeat($i)
}
}
$mailbox|set-mailbox -EmailAddresses $mailbox.EmailAddresses
}
Thanks,
Evan Liu
TechNet Subscriber Supportin forum
If you have any feedback on our support, please contacttngfb@microsoft.comEvan Liu
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
February 14th, 2012 5:59am
You can use this to have a try:
$mailboxes=get-mailbox -resultsize unlimited
foreach($mailbox in $mailboxes)
{
for($i=($mailbox.EmailAddresses.count)-1; $i -ge 0; $i--)
{
$address=$mailbox.EmailAddresses[$i]
$addressString=$address.addressString
if($addressString -like "*@*@*")
{
$mailbox.EmailAddresses.removeat($i)
}
}
$mailbox|set-mailbox -EmailAddresses $mailbox.EmailAddresses
}
Thanks,
Evan Liu
TechNet Subscriber Supportin forum
If you have any feedback on our support, please contacttngfb@microsoft.comEvan Liu
TechNet Community Support
February 14th, 2012 1:44pm
Thank you very much.. this was perfect!
Free Windows Admin Tool Kit Click here and download it now
February 17th, 2012 10:52am