我試圖添加一個用戶,將它們添加到一個組,然後使該組成爲用戶的主組。我一直在使用System.DirectoryServices.AccountManagement進行所有AD訪問。 我已經添加使用用戶:使用System.DirectoryServices.AccountManagement,使組成爲主組
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Globs.strDomain))
{
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName);
group.Members.Add(pc, IdentityType.UserPrincipalName, userId);
group.Save();
}
是否有一個快速的方法來取得該組並使其主要組爲:
principalContext = new PrincipalContext(ContextType.Domain, Globs.strDomain, userOU);
UserPrincipal userPrincipal = new UserPrincipal(principalContext);
userPrincipal.Surname = this.textBox_LastName.Text;
userPrincipal.GivenName = this.textBox_FirstName.Text;
userPrincipal.SamAccountName = this.textBox_LogonName.Text;
userPrincipal.MiddleName = this.textBox_Initials.Text;
userPrincipal.DisplayName = label_DisplayName.Text;
userPrincipal.Description = this.comboBox_Description.Text;
userPrincipal.UserPrincipalName = this.textBox_LogonName.Text;
userPrincipal.SetPassword(defaultPassword);
userPrincipal.PasswordNeverExpires = true;
userPrincipal.Enabled = true;
userPrincipal.Save();
我然後使用用戶添加到組用戶?一旦我創建了主要組,我將刪除默認的「域用戶」組。任何幫助表示讚賞。 -Cary