Vb.net 使用LDAP向AD添加用户
我正在编写一个将用户添加到Active Directory的应用程序。我正在尝试使用此代码连接到广告中的“用户”共享文件夹Vb.net 使用LDAP向AD添加用户,vb.net,active-directory,ldap,Vb.net,Active Directory,Ldap,我正在编写一个将用户添加到Active Directory的应用程序。我正在尝试使用此代码连接到广告中的“用户”共享文件夹 LDAP://celtestdomdc1.celtestdom.local/CN=Users,DC=celtestdom,DC=local 但是,它会将用户添加到共享文件夹中,而不是“用户”共享文件夹中。CN=Users难道不意味着它将把它添加到“Users”文件夹中吗 谢谢如果要创建用户,您需要 绑定到要在其中创建用户的容器 将新用户帐户创建为该容器的子级 只需设置
LDAP://celtestdomdc1.celtestdom.local/CN=Users,DC=celtestdom,DC=local
但是,它会将用户添加到共享文件夹中,而不是“用户”共享文件夹中。CN=Users难道不意味着它将把它添加到“Users”文件夹中吗
谢谢如果要创建用户,您需要
- 绑定到要在其中创建用户的容器
- 将新用户帐户创建为该容器的子级
System.DirectoryServices.AccountManagement
命名空间,使许多事情变得更简单
那么代码看起来就简单了一点:
// create a context for a domain and define "base" container to use
PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
"celtestdom", "CN=Users,DC=celtestdom,DC=local");
// create a user principal object
UserPrincipal user = new UserPrincipal(ctx, "NewUser", "pass@1w0rd01", true);
// assign some properties to the user principal
user.GivenName = "User";
user.Surname = "One";
// force the user to change password at next logon
user.ExpirePasswordNow();
// save the user to the directory
user.Save();
请在此处查看有关System.DirectoryServices.AccountManagement
(S.DS.AM)命名空间的更多信息:
// create a context for a domain and define "base" container to use
PrincipalContext ctx = new PrincipalContext(ContextType.Domain,
"celtestdom", "CN=Users,DC=celtestdom,DC=local");
// create a user principal object
UserPrincipal user = new UserPrincipal(ctx, "NewUser", "pass@1w0rd01", true);
// assign some properties to the user principal
user.GivenName = "User";
user.Surname = "One";
// force the user to change password at next logon
user.ExpirePasswordNow();
// save the user to the directory
user.Save();