新しいユーザー アカウントが作成されてから 90 日で期限切れになるように設定したいと考えています。ユーザーを作成してすべてを設定するコードは次のとおりです。期限切れに設定しようとしている最後のブロックを除いて、すべてが機能します。
DirectoryEntry newUser = dirEntry.Children.Add("CN=" + cnUser, "user");
newUser.Properties["samAccountName"].Value = cnUser;
newUser.Properties["userPrincipalName"].Value = cnUser;
newUser.Properties["pwdLastSet"].Value = 0;
newUser.CommitChanges();
//Changes Password
String passwrd = userPassword.ToString();
newUser.Invoke("SetPassword", new object[] { passwrd });
newUser.CommitChanges();
//Sets User Account to Change Passowrd on new login
newUser.Properties["pwdLastSet"].Value = 0;
newUser.CommitChanges();
//Enables account
newUser.Properties["userAccountControl"].Value = (int)newUser.Properties["userAccountControl"].Value & ~0x2;
newUser.CommitChanges();
//Set the account to expire in 90 days
var dt1 = DateTime.Today.AddDays(90);
newUser.Properties["accountExpires"].Value = dt1.ToFileTime().ToString();
newUser.CommitChanges();
彼の仕事を得る方法について何か提案はありますか?
ありがとう