Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to put data from SQL Server into Active Directory

Posted on 2004-08-26
2
Medium Priority
?
269 Views
Last Modified: 2010-04-15

Just came from the Windows2003 section and it seems that there is nothing usefull to accompligh the job without creating a custom prgram.

So, I need code snippet to help me get on track faster than on my own.
I know that there is a directory class library in the framework.
It would be helpfull to get input from someone who had to use it.

Thank.
0
Comment
Question by:Yann de Champlain
2 Comments
 
LVL 3

Accepted Solution

by:
sohilm earned 2000 total points
ID: 11903922
What exactly are you trying to do?

   Here is an example on how to use system.directoryservices to create a user

using System;
using System.DirectoryServices;

namespace ADAM_Examples
{
    class CreateUser
    {
        /// <summary>
        /// Create ADAM User.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DirectoryEntry objADAM;       // Binding object.
            DirectoryEntry objUser;       // User object.
            string strDisplayName;        // Display name of user.
            string strPath;               // Binding path.
            string strUser;               // User to create.
            string strUserPrincipalName;  // Principal name of user.

            // Construct the binding string.
            strPath = "LDAP://localhost:389/O=Fabrikam,C=US";

            Console.WriteLine("Bind to: {0}", strPath);

            // Get ADAM object.
            try
            {
                objADAM = new DirectoryEntry(strPath);
                objADAM.RefreshCache();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:   Bind failed.");
                Console.WriteLine("         {0}", e.Message);
                return;
            }

            // Specify User.
            strUser = "CN=TestUser";
            strDisplayName = "Test User";
            strUserPrincipalName = "TestUser@Fabrikam.Us";
            Console.WriteLine("Create:  {0}", strUser);

            // Create User.
            try
            {
                objUser = objADAM.Children.Add(strUser, "user");
                objUser.Properties["displayName"].Add(strDisplayName);
                objUser.Properties[
                    "userPrincipalName"].Add(strUserPrincipalName);
                objUser.CommitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:   Create failed.");
                Console.WriteLine("         {0}", e.Message);
                return;
            }

            // Output User attributes.
            Console.WriteLine("Success: Create succeeded.");
            Console.WriteLine("Name:    {0}", objUser.Name);
            Console.WriteLine("         {0}",
                objUser.Properties["displayName"].Value);
            Console.WriteLine("         {0}",
                objUser.Properties["userPrincipalName"].Value);
            return;
        }
    }
}

I suggest getting the LDP.exe utiltiy from the windows 2003 server support tools to checkout what properties you can modify.

I hop this helps.

Thanks
SohilM

0
 

Author Comment

by:Yann de Champlain
ID: 11904924
Thank you.  It will be enough.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question