views:

1684

answers:

3

I try to integrate Human Resource DB to Active Directory. Once I use sql ,getting all person and department and then write to ad. but if a department built new how to check is exist or new in active directory,also person also computer.

A: 

Look at the System.DirectoryServices.AccountManagement namespace. You might also want to look at the Account Management sample application for idea. To check for an OU you can use System.DirectoryServices to instantiate a DirectoryEntry based on the OU's path (or a searcher to find it). If it doesn't exist, you need get the DirectoryEntry object for the parent OU and then create a new OrganizationUnit using Invoke to invoke the ADSI create method.

tvanfosson
A: 

thanks JaredPar for answer. give me sample code in vb.net. I could not find sample code.

while create ou with above code Try

                objOU = objADAM.Children.Add(strOU, "OrganizationalUnit")
                objOU.Properties("description").Add(dr.GetValue(2).ToString)
                objOU.CommitChanges()

            Catch de As Exception
                Console.WriteLine("Error:   Create failed.")
                Console.WriteLine("         {0}", de.Message)
                Return
            End Try
+1  A: 

This article should be helpful: http://www.codeproject.com/KB/IP/LDAP_Using_VBnet.aspx

My thought is that you would create a List of People (OUs) , and once you have such a List, it is very simple to create a function to check the List to see if a specific person exists.

Therefore, If the person does not exist -- CreatePerson()

Otherwise, If the person exists -- UpdatePerson()

Jon