Create user in AD by informing the C# Forms group

Asked

Viewed 37 times

0

Good evening, everyone!

I already have the code user creation in AD with LDAP, and now I want to create this user already informing the group, already researched and I haven’t found the solution yet, I have the following code:

 private static void createUser(string domainAD, 
                                   string nameAD, 
                                   string passwordAD, 
                                   string nameUser, 
                                   string Description, 
                                   string password, 
                                   string OU, 
                                   string DOM, 
                                   string DC)
    {
        PrincipalContext ctx = new PrincipalContext(
                                     ContextType.Domain,
                                     domainAD,
                                     "OU="+OU+",DC="+DOM+",DC="+DC+"",
                                     nameAD,
                                     passwordAD);

        UserPrincipal usr = new UserPrincipal(ctx);

        usr.Name = nameUser;
        usr.Description = Description;           
        usr.SetPassword(password);
        usr.Enabled = true;              
        usr.Save();
        usr.Dispose();
        ctx.Dispose();
    }

Thanks in advance!

  • It’s not clear.

  • @Peter Joy this is my framework for creating a user in AD. First make the connection with the AD through the Principalcontext and then make the creation of the user with the Userprincipal, what I want is to make this creation of the user already informing the group, I did not find the option to insert the user in a certain group already in the creation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.