I have a set of test accounts that are going to be created but the accounts will be setup to require password change on the first login. I want to write a program in C# to go through the test accounts and change the passwords.
+2
A:
Here's a great Active Directory programming quick reference:
Howto: (Almost) Everything In Active Directory via C#
See the password reset code near the end.
Dana Holt
2009-06-30 21:22:17
+2
A:
You can use the UserPrincipal class' SetPassword method, provided you have enough privileges, once you've found the correct UserPrincipal object. Use FindByIdentity to look up the principal object in question.
using (var context = new PrincipalContext( ContextType.Domain ))
{
using (var user = UserPrincipal.FindByIdentity( context,
IdentityType.SamAccountName,
userName ))
{
user.SetPassword( "newpassword" );
}
}
tvanfosson
2009-06-30 21:29:51
That's only available in .NET 3.5 and up, BTW (the PrincipalContext and all).
marc_s
2009-07-04 19:59:12
A:
here is the solution in code :
string newPassword = Membership.GeneratePassword(12, 4); string quotePwd; byte[] pwdBin;
quotePwd = String.Format(@"""{0}""", newPassword);
pwdBin = System.Text.Encoding.Unicode.GetBytes(quotePwd);
UserEntry.Properties["unicodePwd"].Value = pwdBin;
UserEntry.CommitChanges();
;) Mohamed Hachem
Mohamed Hachem
2010-07-20 21:18:39