简体   繁体   中英

How to give path to identify OU when we have nested OU's in active directory while creating a user in active directory in asp.net c#?

Using

PrincipalContext pc = new PrincipalContext(ContextType.Domain, "me.com", "OU=Menetwork OU=Users OU=IT")

I am working on directory programing and I want to know how can I give path for OU when we have nested OUs in active directory while creating a User in active Directory.

A Directory is a tree of objects. Each object OUs (containers), user (leaf in your case) is addressed by a distinguished name wich is composed by an attribute=value pair suffixed by the distinguished name of his container. The following two screenshots show you the two visions, MMC one and the LDAP one with all the DNs.

AD MMC的愿景AD LDP愿景

In my case here is how I can create a user in an nested OU like this :

/* 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(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM