Remove particular SMTP from Mail Contact on Exchange 2010

Hello All,

I am in the process of doing Exchange 2010 crossforest migration for about 1000 user. Due to the target forest having the Source forest as external users when trying to enable mail users it gives that the SMTP address is already taken by the External contacts.

So in order to move users from CSV I tried to automate the process of (Enabling Mail user , If SMTP Proxy is in the Contacts then Delete this SMTP from the contact address but don't delete the contact itself.) I was unable to successfully do it.

I would really appreciate if someone could show me to write a script that would allow me to remove only the SMTP Address that conflicts with the contact in my CSV list.
An example.
I want to Enable-MailUser -Identity identity -Externalmail $Mail

But I get an error that the $Mail is already used by a contact in a particular OU .. I want the script to find the SMTP in that contact and delete ONLY that SMTP from the contact.
Is this possible?


Here is my code

Import-Module activedirectory

# 1- Disable and Enable Mail-User after ADMT Migration
#The Value $User.proxy stands for the user's Primary SMTP Address
# $User.Alias is taken from the Columns inside the of the list.csv file

$Users = import-csv -path "C:\CrossForestMigration\List-1\List.csv"

foreach ($user in $Users)
$Identity = $user.Alias
$Mail = $user.proxy

Disable-MailUser -Identity $User.alias

# 2- Remove SMTP from Contact object

Set-ADObject -Identity $user.alias -Replace @{proxyAddresses=$null}

[b]#This didn't work[/b]
#Set-ADUser -Identity $Identity -Add @{Proxyaddresses="SMTP:"-"$($user.Proxy)"}

#Enable Mail User
Enable-MailUser -Identity $Identity -ExternalEmailAddress $Mail

#Prepare MoveRequest
cd $exscripts
Write-Host "Enter Remote Credentials ...." -ForegroundColor Green -BackgroundColor Black
$RemoteCredentials = Get-Credential
$RemoteCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $RemoteCredentials 
$TargetCredentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $TargetCredentials

Open in new window

LVL 24
Mohammed HamadaSenior IT ConsultantAsked:
Who is Participating?

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

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.

if target already has external contact with same SMTP address you are trying to put-up on mail enabled user, just delete contact from target, what is problem in doing that as you are removing SMTP from contact, I mean then what is the use of modified contact?

The other way around is to use preparemoverequest.ps1 exchange native script which actually convert target contact into mail enabled user provided that user is not already exists in target
Then use ADMT to merge SID History of source user to target user which will eventually be used to retain resource access during co-existence and migration
Mohammed HamadaSenior IT ConsultantAuthor Commented:
The scenario here is not a usual Crossforest Migration. it's more complicated since there are different factors that changes how the mirgation is supposed to work. The client I am doing the project for already created destination users with another tool which they are using to get users from SAP.

In my end I am using ADMT with CSV files to overwrite the already created users (different UPN) to get sID History into this created user. Contacts were already created between two forests prior to start this project.

I already have tried to delete contacts prior to migrating users but apparently users started to get X500 failure messages. Then rolled back delete from backup to fix the issue.

Now I have adjusted the script to change the primary SMTP address of the contact from to domain.local since the script didn't accept simply removal of the Primary SMTP ..

This have worked perfectly for me:

$Users = import-csv -path "C:\New_LIST_01.csv"
foreach ($User in $Users)
$Identity = $User.Alias
$Mail = $User.Proxy
$NProxy = $User.NewProxy
$NIdentity = $User.NewIdentity
#-2 Disable Mailuser and Mailbox if exists (Created users by IDM App) 
Write-host = $User.proxy will be Mailuser disabled -ForegroundColor Green -BackgroundColor Black
Disable-MailUser -Identity $User.Proxy
Write-host = $User.proxy will be Mail disabled -ForegroundColor Green -BackgroundColor Black
Disable-Mailbox -Identity $User.NewIdentity -Confirm
# 3- Remove SMTP from Contact object
Set-MailContact -Identity $User.proxy -EmailAddresses $NProxy
# 4- Enable Mail User
Enable-MailUser -Identity $User.NewIdentity -ExternalEmailAddress $Mail

Open in new window


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
Mohammed HamadaSenior IT ConsultantAuthor Commented:
Solved it by changing the primary SMTP for the contact.
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

From novice to tech pro — start learning today.