pking Posted January 22, 2014 Posted January 22, 2014 Hi All, So i have been playing with a powershell to reset a domain user password. which worked perfectly. Now trying to create it in c# with visual studio (nicer for the other people who will need to change a password), but can seem to figure out where its going wrong. Any off you able to lay fresh eyes on it? private void button1_Click(object sender, EventArgs e) { string username = UserTxtbox.Text; string newpassword = PwdTxtbox.Text; { DirectoryEntry user = new DirectoryEntry(username); user.Invoke("SetPassword", new object[] { newpassword }); user.Close(); } } Here is the powershell version i have working $password = (ConvertTo-SecureString -AsPlainText "Passw0rd123" -Force) $credential = New-Object System.Management.Automation.PSCredential "domain.local\admin",$password $user = Read-Host "Type username:" $newpassword = Read-Host "Type password:" -AsSecureString Set-ADAccountPassword –Identity $user -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $newpassword –Force)
matt40k Posted February 7, 2014 Posted February 7, 2014 Try: private bool ResetUserPassword { get { try { // Create an Instance of DirectoryEntry. DirectoryEntry myDirectoryEntry = new DirectoryEntry("LDAP://domain.local"); myDirectoryEntry.Username = this.UserTxtbox.Text; myDirectoryEntry.Password = this.PwdTxtbox.Text; } catch (Exception) { return false; } return true; } }
mac_shinobi Posted February 7, 2014 Posted February 7, 2014 Not that it helps with the coding question but why re-invent the wheel when there is : BCX Password Reset by Burconix : Reset Student User Password Free Tool for Schools, Business and Education - Burconix Password Control by Wisesoft : WiseSoft - Password Control. Active Directory Password Reset Tool.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now