0

ユーザーを追加してグループに追加し、そのグループをユーザーのプライマリ グループにしようとしています。すべての 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」のデフォルト グループを削除します。どんな助けでも大歓迎です。-キャリー

4

1 に答える 1

0

それは属性primaryGroupIDによって制御されます。デフォルトでは公開されていないため、それを公開する独自のサブクラスを作成するUserPrincipalか、より多くの RAW 基になるオブジェクトを使用して属性を設定する必要があります。System.DirectoryServices

(更新: MSDNマガジンの 2008 年以前の記事は、Web インターフェイスからは利用できなくなりました。サブクラスの作成に関する記事を参照してください)

属性値はグループの RID であるため、新しいグループからprimaryGroupToken属性を取得し、usersprimaryGroupID属性に設定する必要があります。

于 2013-07-09T20:36:01.247 に答える