Home > Active Directory, MS Technologies > How to set default smtp addresses for Active Directory contacts using Powershell

How to set default smtp addresses for Active Directory contacts using Powershell


Hi again,

We are working currently on a critical migration project from a Windows 2003 Platform to Windows 2008/2012/R2. We had also to migrate Exchange 2003 to Exchange 2010. We had encountered some troubles and everything is working fine after some resolutions (ElhamdouliLLah!).

One of the encountered problems concerned a big number of Exchange 2003 contacts (created in Active Directory) that could not be opened in Exchange 2010. The cause is that the default primary SMTP address of these contacts was not set. Consequently, it was not possible to send mails to those contacts. We had more than 700 contacts to update. In our 2012 Domain controlers we had to modify the proxyAddresses attribute for each contact which contains initially two addresses : X400 and smtp.

To set a default SMTP address, the “smtp” keyword has to be changed by the “SMTP” word.

Let us suppose that we have an OU containing all our contacts and named “EXP Contacts” in the “contoso.com” domain. You can find some PS scripts just for Active Directory Users. The idea is the same but with the contacts things are a bit different.

The Powershell script to execute on a domain controller or an Exchange server after importing Active Directory modulle is as follows :

$EXPOUPath=”ou=EXP Contacts , dc=contoso, dc=com”;

$EXPContacts = Get-ADObject -Filter ‘objectClass -eq “contact”‘ -searchbase $EXPOUPath -Properties *

foreach ($EXPContact in $EXPContacts)
{
$proxyAdresses=$EXPContact.proxyAddresses;

foreach ($EXPContactPrxAddress in $proxyAdresses)
{
if ($EXPContactPrxAddress -match “^smtp”)
{
$EXPContactCN=”cn=”+$EXPContact.CN+”,”+$EXPOUPath;
Set-ADObject CN -Remove @{ProxyAddresses=$EXPContactPrxAddress}
$EXPContactDefaultAddress=”SMTP:”+$EXPContactPrxAddress.Split(“:”)[1];
Set-ADObject CN -Add @{ProxyAddresses=$EXPContactDefaultAddress}
}
}
}

Hope it helps.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: