Mohammed Hamada
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Solved it by changing the primary SMTP for the 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