开发者

cannot create new object in ActiveDirectory

I'm trying to add new object to existing organisational unit in Active Directory. Following code is used to do this.

It runs without errors. But new object is not created after this. Please advise what I'm doing wrong here.

using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;

namespace TestAdObjectCreation
{
    class Program
    {
        static void Main(string[] args)
        {
            Dir开发者_运维知识库ectoryEntry root = new DirectoryEntry("LDAP://servername/OU=Services,OU=PCX,DC=q2q,DC=xenyq,DC=com", "Administrator", "pass");
            DirectoryEntry newItem = root.Children.Add("test_node", "valid_schema_class_name");
            root.CommitChanges();
            root.Close();
            root.Dispose();
        }
    }
}


What kind of object are you trying to create??

First of all, all LDAP object always have a prefix, DC= for domain component, OU= for organizational unit, CN= for common name.

Also, many LDAP objects have minimal requirements for what they need to be considered valid; e.g. a user or a group must have a unique samAccountName.

So again - what are you trying to create??

If you wrap your creation code into a try..catch - do you get any exceptions? If so - what are they??

static void Main(string[] args)
{
    DirectoryEntry root = new DirectoryEntry("LDAP://servername/OU=Services,OU=PCX,DC=q2q,DC=xenyq,DC=com", "Administrator", "pass");

    try
    {
        DirectoryEntry newItem = root.Children.Add("CN=test_node", "valid_schema_class_name");

        root.CommitChanges();
    }
    catch(Exception exc)
    {
       string error = exc.GetType().FullName + ": " + exc.Message;
    } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜