PowerShell

In this article:
Change Local Administrator password using PowerShell on single computer.
Change Local Administrator account password using PowerShell on multiple computer

There are multiple ways to change your local Administartor account password. In this article, I will show you how to change local Administrator Password using PowerShell command.

Before we continue. here are a nice little tips for your Windows System.

  • You should always be careful regarding password change.
  • To avoid being in trouble, you should change your password frequently. It reduces the chances of getting hacked.
  • Use complex character combination for your password.
  • Disable Administrator account and create another user with Administrator privileges. Having another user with Administrators privileges could help you in many case.

Change Local Administrator password using PowerShell on a single computer

Open PowerShell with elevated permission and run the command below

$password = Read-Host "Enter the new password:" -AsSecureString
Get-LocalUser -Name "Administartor" | Set-LocalUser -Password $password

Change Local Administrator account password using PowerShell on multiple computer

Change Local Administrator password on multiple computer could take your time. Using powershell command can help you to finish this job easily. Below is the PowerShell command/script to do that based on the list of the computers.

Get Input Password

First step, we need to capture the password input and save it on the variable as secure string.

$Password = Read-Host "Enter the New Password" -AsSecureString
$ConfirmPassword = Read-Host "Confirm the New Password" -AsSecureString

$pwd1 = [Runtime.InteropServices.Marshal]::PtrToStringAuto([RunTime.InteropServices.Marshal]::SecureStringToBSTR($Password))
$pwd2 = [Runtime.InteropServices.Marshal]::PtrToStringAuto([RunTime.InteropServices.Marshal]::SecureStringToBSTR($ConfirmPassword))

if ($pwd1 -ne $pwd2){
write-host "The passwords are not Match. Exit the script"
exit
}

Get the list of the computers

Now, to get the list of the computers, we will use Get-Content cmdlet.

$Computers = $Get-Content -Path $FileLocation

For the $FileLocation variable, you can Open File Dialog Box or using static location.

Changing The Administartor Password on Multiple Computers

After we have a list of computers, we can use PowerShell looping to run password change command

foreach ($computer in $computers){
try{
$account = [ADSI]("WinNT://$computers/Administartor.user")
$account.psbase.invoke("setpassword",$pwd1)
Write-Host = "Password has been succesfully changed"
}catch{
Write-Host "Oops, There is an error: $_"
}
}

If you like this article, please share, subscribe or you can follow our Facebook Page and Twitter.