使用C#在AD中创建用户 [英] Create user in AD with C#

查看:397
本文介绍了使用C#在AD中创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我试着用我的代码在AD中创建用户,我有一个标准代码创建一个用户,但我想添加一些东西,如SamAccountName + firstname + Lastname,所有代码现在都是创建一个名为TESTUSER的用户没有任何samaccount / passowrod等



使用System; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;使用System.DirectoryServices
;


命名空间ConsoleApplication1
{
class程序
{
static void Main(string [] args)
{


string ADFullPath =LDAP://192.168.0.10/OU=T2,OU=root,DC=admin,DC=domain,DC=com;
DirectoryEntry ouEntry = new DirectoryEntry(ADFullPath,admin,passw0rd,AuthenticationTypes.Secure);


for(int i = 0; i< 1; i ++)
{
try
{
DirectoryEntry childEntry = ouEntry。 Children.Add(CN = TESTUSER+ i,user);
childEntry.CommitChanges();
ouEntry.CommitChanges();
childEntry.Invoke(SetPassword,new object [] {password22});
childEntry.CommitChanges();

}
catch(exception ex)
{


}


}


}
}
}

解决方案

你有没有打扰过做任何实质性研究?关于如何以各种形式进行此操作有数百篇文章。

这个网站上甚至还有一些。



实际上这个:



Howto :(几乎)通过C#在Active Directory中的所有内容 [ ^ ]



来自Google搜索c#active directy user创造(是的,我甚至拼错目录并找到它)。



它应该告诉你需要知道的一切。


< blockquote>我实际上只阅读了那篇文章,但是尽管有很多人尝试过这篇文章,但有些东西却无效。例如,名为create_user.cs:的部分

它应该创建一个AD用户,但它会在控制台中生成很多错误。



所以我发现这个代码我刚刚发布,实际上有效,但我需要添加一些功能,这就是为什么我问=)


Hello im trying to create users in the AD with my code, i have a standard code that creates a user, but i would like to add some things such as SamAccountName + firstname + Lastname, all the code does now is to create a user called "TESTUSER" without any samaccount/passowrod etc

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {


            string ADFullPath = "LDAP://192.168.0.10/OU=T2,OU=root,DC=admin,DC=domain,DC=com";
            DirectoryEntry ouEntry = new DirectoryEntry(ADFullPath, "admin", "passw0rd", AuthenticationTypes.Secure); 


            for (int i = 0; i < 1; i++)
            {
                try
                {
                    DirectoryEntry childEntry = ouEntry.Children.Add("CN=TESTUSER" + i, "user");
                    childEntry.CommitChanges();
                    ouEntry.CommitChanges();
                    childEntry.Invoke("SetPassword", new object[] { "password22" });
                    childEntry.CommitChanges();
                    
                }
                catch (Exception ex)
                {


                }


            }


        }
    }
}

解决方案

Have you bothered to do any substantial research? There are hundreds of articles on how to do this in various forms.
There are even a few on this site.

Infact this one:

Howto: (Almost) Everything In Active Directory via C#[^]

Comes top of a Google search for "c# active directy user creation" (Yes I even spelt directory wrong and it found it).

It should tell you everything you need to know.


I have actually read just that article, but as many who tries it, some things there doesn't work. For example the section called "create_user.cs:"
It's supposed to create a AD user but instead it generates alot of errors in the console.

So i found this code that i just posted now, which acctually work's but i need to add some features to it that's why i asked =)


这篇关于使用C#在AD中创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆