Using Directory Services information to generate a Telephone List

2010-01-03 21:25 PST

My organization creates a list of four digit extension numbers of all the employees in the organization, every year or so. The purpose of course is to provide a quick reference list, next to every telephone in the building. Until recently, the list has been maintained manually, and over time it has become an unruly mess of fonts, tabs and various styles. I have found it to be quite useless for some time.

Last year I decided to tackle this issue, and automate the list generation. My first attempt, was significantly better than the original manually generated list, but was less than ideal. It boiled down to running csvde with a long list of arguments on one of my domain controllers in order to generate a .csv file that contained more information than I needed. Then I moved that file to my mac, and through the use of some shell scripting I was able to trim the un-needed information out of the file and create a new, filtered, .csv file Following that, I was able to take the filtered .csv and run it through a mail merge document that I created in Word.

It worked, it generated the document exactly the way I wanted it. However, there were a few things I didn’t like. My biggest gripe was that I had to use both the Win 2K3 Domain Controller (to generate the first file) and then had to use my Mac to process that file and ultimately generate the word document.

Over Christmas break this year, I set out to resolve that issue, and do some learning on a couple of topics that have interested me for a while now.

Apple has provided a command line utility called dscl (Directory Services Command Line) for at least the last two major releases of OS X. I have only just learned what it can do for me. I found it to be quite useful in pairing down the number of steps required to generate the telephone list.

Here is a copy of the script, fairly well commented, for ease of understanding.