Does anyone know how can I reset password for Active Directory in C#?
I wrote the following code to reset the password in Active Directory:
[WebMethod] public static string ResetPassword(string test) { string userDn = "CN=Joe Bloggs,OU=Test Accounts,OU=ST IT,OU=Departments,OU=Internal,OU=Divisions,DC=thegroup,DC=com,DC=au"; string password = "!qwer12345"; DirectoryEntry uEntry = new DirectoryEntry(userDn); uEntry.Invoke("SetPassword", new object[] { password }); uEntry.Properties["LockOutTime"].Value = 0; //unlock account uEntry.Close(); return "hello"; }
When I run the code, an error displays when it reaches the line uEntry.Invoke("SetPassword", new object[] { password });
Does anyone know what's causing this issue and how I could fix it?