Steve Goodman's Exchange Blog
20Feb/123

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've written 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:


GeSHi Error: GeSHi could not find the language powershell (using path /home/content/03/9366303/html/wp-content/plugins/codecolorer/lib/geshi/) (code 2)

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..

Related posts:

  1. Using Powershell to import contacts into Exchange and Outlook Live
  2. Testing edge blocking in Forefront Online Protection for Exchange using Powershell
  3. How to batch optimize your Exchange GAL Photos before importing to Active Directory
  4. How to export Email Headers from Exchange using Powershell
  5. Report your Exchange Offline Address Book Sizes using Powershell

Posted by Steve Goodman

Comments (3) Trackbacks (1)
  1. Hey,

    great script – but: can you extend the script to import the contacts of GAL too? and not only users ?

    regards

    • Hi Marcy,

      Yes, you should be able to fairly easily. I’d check out the source of the code and look for where it is using normal Exchange Powershell to “get” users. Any problems, give me a shout and I can do a special update for you.

      Steve

  2. Figures. I spent a weekend hand-creating a CSV file from scratch for this same purpose a few months ago.

    This is really useful though, and it’s not just useful for reaching out, but even having the directory in Contacts helps identify callers too, which is really useful.

    I’m curious… does this grab the user picture too?


Leave a comment

(required)