Saturday, April 7, 2012

Importing Global Address List entries into a user’s Contacts folder

I had a fairly unusual request from one of my customers whilst performing the final stages of an Exchange migration. A while ago, the CEO wasn't able to lookup people to contact from the Global Address List due to connectivity problems and wanted "offline" access to the GAL from his phone.
The customer asked me if it would be possible for me to write a little script to effectively grab the GAL (they aren't a massive company) and copy it into the CEO's mailbox, into a dedicated Contacts folder, for example "OrgContacts". Whilst certainly not a great idea for a larger company, for a few hundred users it's not a bad idea, and in a previous post I'vewritten something very similar, so in my spare time put together the following script…
What it does:
  • Connects to the user mailbox using EWS as a the logged on Administrator, using impersonation.
  • Checks if the dedicated contacts folder exists, and if so empties it.
  • Gets the organization's users who have an email address set and at least a work phone or mobile phone number.
  • Adds a contact for each of the above users, populating the contact's name, company, department, job title, email address and work and mobile phone numbers into the dedicated contacts folder.
Pre-requisites
As with the original script this is based on, you need to set up the impersonal for Exchange Web Services and install the Exchange Web Services Managed API 1.2 before using the script. The script uses the default installation location of the EWS Managed API, so if you've got it installed somewhere else, update the script.
To setup the pre-reqs, follow Setup of Exchange Web Services Impersonation and Installing the Exchange Web Services Managed API from the original article Using Powershell to import contacts into Exchange.
Additionally, the script expects to be used in the following scenario:
  • To be executed from the Exchange Management Shell, so it can get the InternalURL for Exchange Web Services (EWS) from Exchange 2010 SP1 or SP2.
  • The logged-in user is the administrator whom has impersonation rights over the mailbox you wish to copy contacts into.
Using the Copy-OrgContactsToUserContacts.ps1 Script
Once the pre-reqs are satisfied, run the script using the following parameters, substituting <mailbox> with the name of the Mailbox User you wish to create the Contacts folder within:
.\Copy-OrgContactsToUserContacts.ps1 -Mailbox <mailbox> -FolderName OrgContacts
Upon initial and subsequent executions, the script should output similar to shown below:
image
Finally, the new contacts folder, complete with copies of GAL entries should show within the user's mailbox, as shown below in OWA:
image
Download the Copy-OrgContactsToUserContacts.ps1 here as a zip file, and as always if you've got any questions or suggestions for improvement, let me know in the comments below..

No comments:

Post a Comment