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.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With