Mail enable Active Directory contacts in Exchange with a PowerShell oneliner

Last week a community peer asked me on Facebook to assist him with a challenge.

His issue was that he had imported contacts into Active Directory by using a tool named “ldifde”. This tool also filled in the email address on the contact object in Active Directory.
But, he wanted to mail-enable them within Microsoft Exchange Server and set the mail address filled in the ‘Email address’ attached to the contact as the external mail address.
Since we’re talking about 2000+  contacts, this is not something you want to do by clicking… so we turned to PowerShell.Emoticon met brede lach

And here’s the PowerShell oneliner to do this.

Get-Contact -RecipientTypeDetails Contact -Filter ‘WindowsEmailAddress -ne $null’ | foreach { enable-mailcontact -Identity $_ -ExternalEmailAddress $_.WindowsEmailAddress.toString() }

Note that this command will search through your entire AD… use the –OrganizationalUnit parameter to search more specific. Knipogende emoticon
Now, this command took about 15 minutes to run… for about 2300 contacts. A lot better compared to clicking them manually, right? Verhitte emoticon

Note: Getting an error stating that the “Get-Contact” cmdlet is unknown? Be sure that you’re a member of the “Exchange View-Only Administrators” group!

Leave a Reply

Your email address will not be published. Required fields are marked *