• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 71
  • Last Modified:

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?

Thanks

Here is my code

Start-Transcript
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

0
Mohammed Hamada
Asked:
Mohammed Hamada
  • 2
1 Solution
 
MaheshArchitectCommented:
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
1
 
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 @domain.com 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

0
 
Mohammed HamadaSenior IT ConsultantAuthor Commented:
Solved it by changing the primary SMTP for the contact.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now