mrichmon
asked on
Add a user to an active directory group
How do I use the IADsGroup.Add function to add a user to a security group in my windows domain.
I have added the user to the domain as follows:
DirectoryEntry de = new DirectoryEntry();
// Set credentials of an AD account that is priveledged to be able to create users
de.Username = username;
de.Password = password;
// Set active LDAP path
de.Path = LDAPpath;
// Assign the users in the LDAPpath to a variable so we can manipulate it (add users)
DirectoryEntries users = de.Children;
// Add user account
DirectoryEntry user = users.Add("CN=" + LastName + "\\, " + FirstName, "user");
// Set additional properties of new account
user.Properties["samAccoun tName"].Ad d(username ); // Login name
user.Properties["givenName "].Add(Fir stName); // First Name
user.Properties["sn"].Add( LastName); // Last Name
// Commit changes
user.CommitChanges();
ActiveDs.IADsUser tester = (ActiveDs.IADsUser)user.Na tiveObject ;
tester.ChangePassword("", Mypassword);
// Commit password changes
user.CommitChanges();
Now how do I add this user to the security group named :
My Standard Group
Thanks!
I have added the user to the domain as follows:
DirectoryEntry de = new DirectoryEntry();
// Set credentials of an AD account that is priveledged to be able to create users
de.Username = username;
de.Password = password;
// Set active LDAP path
de.Path = LDAPpath;
// Assign the users in the LDAPpath to a variable so we can manipulate it (add users)
DirectoryEntries users = de.Children;
// Add user account
DirectoryEntry user = users.Add("CN=" + LastName + "\\, " + FirstName, "user");
// Set additional properties of new account
user.Properties["samAccoun
user.Properties["givenName
user.Properties["sn"].Add(
// Commit changes
user.CommitChanges();
ActiveDs.IADsUser tester = (ActiveDs.IADsUser)user.Na
tester.ChangePassword("", Mypassword);
// Commit password changes
user.CommitChanges();
Now how do I add this user to the security group named :
My Standard Group
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.