in

ASP.NET Weblogs

Brian Desmond's Blog

Inherits Network.Admin
Implements IOneManBand

Creating a Contact in AD

Well, this new Agg Views thing indicates that my babbling about Active Directory stuff is mildly interesting, so, I'm continuing the series here. This morning's task is creating a contact in AD. Before we get going, let me give a brief overview of my take on what Contacts are for. Feel free to reference the Platform SDK for whatever the official word is.

Without an Exchange Server, I think contacts are pretty darn useless, unless you intend to keep the corporate rolodex in AD, which, I guess is feasible. A contact is like a user, except it doesn't have an account in your domain. Contacts have all the attributes a contact in your rolodex would have - name, address, email, phone, etc. But, unlike a user, they cannot log on to the domain. When an Exchange Server comes into play, contacts become a lot more useful. You can do a couple of things with them - create a forwarding address for a user object, or simple create a forwarding address. They also are ten times as useful as a “contact” in the corporate rolodex, as they can be displayed in the GAL along with other users.

So, here's what we're going to do: create a contact object in AD. You can follow this example pretty easily and modify it to create a user or a group if you want. Tomorrow (or next time), we'll dive into CDOEXM and mail enable the contact, and setup a user with forwarding. Not sure what's next - perhaps create a user & a mailbox to go along with it.

First thing we're going to do is setup a directoryEntry for the OU we're creating the contact in. We'll create our contact in an OU called Contacts in the root of our domain MyDomain.local:

Dim root as new DirectoryEntry(LDAP://OU=Contacts,DC=MyDomain,DC=local)

The key to creating something in AD is to create another DirectoryEntry off of the Add method of our root's Children property:

Dim myContact as DirectoryEntry = root.Children.Add("CN=Jane Doe", "contact")

What we've done here is created a new container of class contact inside the Contacts OU. I always name my contacts and user CNs the same as their display name in the GAL. So, Jane Doe's contact object is in container (CN) Jane Doe.

Now we can set some properties. I'm just going to set the first (givenName) and last (surName) name attributes like we did last night. For demo, I'll also set Jane's home phone to 773-555-1212 (that's Chicago directory assistance if you want to call)

myContact.Properties(”givenName”).Value = “Jane”
myContact.Properties(”sn”).Value = “Doe”
myContact.Properties(“homePhone“).Value = “773-555-1212“
myContact.CommitChanges()

This is the same as last night - nothing to go over, just remmeber to call CommitChanges(), or nothing will get pushed to the directory.

So, in conclusion, we've used the code below to create a contact for Jane Doe in the Contacts organizational unit (OU), whose home phone is 773-555-1212. 

Dim root as new DirectoryEntry(“LDAP://OU=Contacts,DC=MyDomain,DC=local“)
Dim myContact as DirectoryEntry = root.Children.Add("CN=Jane Doe", "contact")
myContact.Properties(”givenName”).Value = “Jane”
myContact.Properties(”sn”).Value = “Doe”
myContact.Properties(“homePhone“).Value = “773-555-1212“
myContact.CommitChanges()

Published Dec 29 2003, 12:54 AM by bdesmond
Filed under: ,

Comments

 

Feed Search Engine - All Fresh Articles And News Are Here said:

Pingback from  Feed Search Engine - All Fresh Articles And News Are Here

November 25, 2007 6:03 PM

Leave a Comment

(required)  
(optional)
(required)  
Add