使用
PrincipalContext pc = new PrincipalContext(ContextType.Domain, "me.com", "OU=Menetwork OU=Users OU=IT")
我正在进行目录编程,我想知道,当我们在active directory中创建用户时,在activedirectory中嵌套ous时,如何为ou提供路径。
最佳答案
目录是对象树。每个对象ous(containers)、user(在您的例子中是leaf)都由一个可分辨名称寻址,它由一个attribute=value
对组成,以其容器的可分辨名称作为后缀。下面的两个屏幕截图显示了两个视图,mmc one和ldap one以及所有dns。
在我的例子中,我可以这样在嵌套的ou中创建用户:
/* Creating a user
* Retreiving a principal context
*/
PrincipalContext domainContextMonou = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "ou=SousMonou,ou=Monou,dc=dom,dc=fr", "user", "pass");
/* Create a user principal object
*/
UserPrincipal aSlxUser = new slxUser(domainContextMonou, "user3.users", "pass@1w0rd01", true);
/* assign some properties to the user principal
*/
aSlxUser.GivenName = "user3";
aSlxUser.Surname = "users";
/* Force the user to change password at next logon
*/
//aSlxUser.ExpirePasswordNow();
/* save the user to the directory
*/
aSlxUser.Save();
/* set the password to a new value
*/
aSlxUser.SetPassword("test.2013");
aSlxUser.Save();