ユーザーを追加してグループに追加し、そのグループをユーザーのプライマリ グループにしようとしています。すべての AD アクセスに System.DirectoryServices.AccountManagement を使用しています。次を使用してユーザーを追加しました。
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();
次に、次を使用してユーザーをグループに追加します。
using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, Globs.strDomain))
{
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, groupName);
group.Members.Add(pc, IdentityType.UserPrincipalName, userId);
group.Save();
}
そのグループを取得して、ユーザーのプライマリ グループにする簡単な方法はありますか? プライマリ グループを作成したら、「Domain Users」のデフォルト グループを削除します。どんな助けでも大歓迎です。-キャリー