Reset your AD password back to original

For the below code to work you’ll need to install in Windows Features all items under Remote Server Administration Tools:
Screen Shot 2014-04-21 at 9.37.29 AM

The parameters to call this are as follows:
-user [Your AD username]
-current [Your current AD password]
-new [The new AD password you want, can be the current AD password]

Import-Module ac*
param ( [string] $user, [string] $current, [string] $new)
if($user -eq "") {
    $user=Read-Host "Enter the username"

if($current -eq "") {
    $current=Read-Host "Enter the current password"

if($new -eq "") {
    $new=Read-Host "Enter the new password"

for ($i=1; $i -le 6; $i++)
    $temppass = "p0A#s4s4" + [string]$i
    if($i -eq 1) {
        Set-ADAccountPassword $user -OldPassword (ConvertTo-SecureString -AsPlainText $current -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $temppass -Force)
    else {
        $previous = "p0A#s4s4" + [string]($i - 1)
        Set-ADAccountPassword $user -OldPassword (ConvertTo-SecureString -AsPlainText $previous -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $temppass -Force)

Set-ADAccountPassword $user -OldPassword (ConvertTo-SecureString -AsPlainText $temppass -Force) -NewPassword (ConvertTo-SecureString -AsPlainText $new -Force)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s