I have an exchange server 2010 running, and want to programmatically add contacts into the server. What is the way to achive this?

Best to be done in Java, but VB6 would be okay, too.


When you say "add contacts into the server", what exactly do you mean?

Exchange doesn't contain contacts itself. You can add contacts to active directory to be visible in the global address book for all exchange users. There's sample code to do this here.

Alternatively you can add contacts to an individual user's contacts in outlook, which will make them available to that individual user - you can of course run this script for several users if you want to make the contacts available to more than one person. Not tested this one, but there's sample code available here to get you started.

If you go with the first route and have a large number of contacts to add then you may end up with a Global Address List (GAL) that is very large and difficult to use, and the unpleasant prospect of emails intended for internal use only sent to external people who are in your contacts list. It's possible to prevent this by creating more than one view of the GAL - one that includes contacts and one that only includes Windows accounts (aka 'full' exchange users).

You can use the Exchange Management Shell to manipulate the GAL as follows (example from technet forums)

Get-GlobalAddressList "Default Global Address List" |FL *Filter

you will see a filter like:

{(Alias -ne $null -and (ObjectClass -eq 'user' -or ObjectClass -eq 'contact' -or ObjectClass -eq 'msExchSystemMailbox' -or ObjectClass -eq 'msExchDynamicDistributionList' -or ObjectClass -eq 'group' -or ObjectClass -eq 'publicFolder'))}

I've highlighted where the default GAL's filter includes contact objects too, because of the condition ObjectClass -eq 'contact'.

So if you want that your default GAL exclude these contacts object then you will have to reset the Recipient Filter of your GAL like this:

Set-GlobalAddressList "Default Global Address List" -RecipientFilter {(Alias -ne $null -and (ObjectClass -eq 'user' -or ObjectClass -eq 'msExchSystemMailbox' -or ObjectClass -eq 'msExchDynamicDistributionList' -or ObjectClass -eq 'group' -or ObjectClass -eq 'publicFolder'))}

and then you can create some other GAL for the contacts similar to this:

New-GlobalAddressList "Contacts Global Address List" -RecipientFilter {(Alias -ne $null -and ObjectClass -eq 'Contact')}

As I work at a college, we've played about with examples similar to the above ones to control what students can and cannot see in the GAL, so I know the principles work, you'll just need to fiddle and test the filters until you get a result you're happy with. We're using Exchange 2007 but for things like this there shouldn't be any significant differences.

| improve this answer | |
  • +1 this is good answer, IMHO, because it tells me that I simply have to sync with the AD and push our contact information there. Btw, do you know about the behaviour of Exchange if it contains 25000 contacts? :) – Daniel Feb 4 '11 at 9:26
  • @Daniel 25000 contacts is a bit rich for my blood, but I think Microsoft have whitepapers where they've done things like that (come to that, wouldn't their own internal address book or that of their big customers come close?) – Rob Moir Feb 4 '11 at 9:31
  • I just wondered if it would be feasible for large corporations to sync our ERP address book with their Exchange Server. But for all smaller companies with a few hundred contacts I would see no problems. – Daniel Feb 4 '11 at 10:09
  • @Daniel - in that case you can create two views of the global address book, one that excludes contacts so its just your internal employees as normal, and another view for the contacts you have added. I'll edit my answer to add notes and links for this. – Rob Moir Feb 4 '11 at 10:30
  • +1 great info! This allows for me to spit between supplier and customer contacts (and prospectives)! – Daniel Feb 4 '11 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.