How to programmatically change Active Directory password

后端 未结 6 1498
执念已碎
执念已碎 2020-11-27 14:28

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

6条回答
  •  独厮守ぢ
    2020-11-27 14:55

    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.

    public void ResetPassword(string userDn, string password)
    {
        DirectoryEntry uEntry = new DirectoryEntry(userDn);
        uEntry.Invoke("SetPassword", new object[] { password });
        uEntry.Properties["LockOutTime"].Value = 0; //unlock account
    
        uEntry.Close();
    }
    

提交回复
热议问题