Solved

Need to put data from SQL Server into Active Directory

Posted on 2004-08-26
2
213 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
2 Comments
 
LVL 3

Accepted Solution

by:
sohilm earned 500 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, PMP
ID: 11904924
Thank you.  It will be enough.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now