Change your windows account password by powershell script

1.Enabel windows feature

Makes sure you have already install the Set-AdAccountPassword feature, or install it by follows

Import-Module ServerManager

2.Run script

Create file: .\change_password.ps1

param (
    [string]$domain = "domain",
    [string]$userName = "account",
    [string]$oldPassword = "old_password",
    [string]$newPassword = "new_password"
)
sleep 10

$SeOldPassword = ConvertTo-SecureString -AsPlainText $oldPassword -Force
$SeNewPassword = ConvertTo-SecureString -AsPlainText $newPassword -Force

$Credential = New-Object System.Management.Automation.PSCredential ("$domain\$userName", $SeOldPassword)

#gwmi win32_service -credential $MySecureCreds -computer PC#
Set-AdAccountPassword -Credential $Credential -Server $domain -Identity $userName -OldPassword $SeOldPassword -NewPassword $SeNewPassword

Then run command:

.\change_password.ps1 {yourDomain} {yourAccount} {yourOldPassword} {yourNewPassword}

Be the first to comment

Leave a Reply

Your email address will not be published.


*