PowerShell : change local Administrator password
Solution 1
When I wanted to change local admin password accross all the servers in AD domain I simply used PS remoting which allows pushing even very basic commands from CMD to remote server.
I wrote a short script where I use powershell to obtain info from domain controller and based on certain conditions push command to the servers.
I find it as really easy and fast way how to change local admin password. The only requirement is to have WinRM enabled on all the servers.
The script is below here:
Invoke-Command -ScriptBlock {net user administrator "Password01"} -ComputerName (Get-ADComputer -SearchBase "OU=test,OU=servers,DC=lab,DC=com" -Filter * | Select-Object -Expand Name)
Solution 2
Have not tested this but i found
([adsi]“WinNT://<Local or Remote Computer Name>/<Username>”).SetPassword(“<Password>”)
http://www.petri.co.il/how-to-change-user-password-with-powershell.htm
Solution 3
If your goal is really to change the password for the Administrator account (regardless of whether it's been renamed--it is not always named 'Administrator'), I recommend using a script like the one in this article:
Windows IT Pro: Resetting the Local Administrator Password on Computers
The Reset-LocalAdminPassword.ps1
script uses ADSI to connect to remote systems, so it is presumed that remote administration is permitted through the remote computer's firewall.
Since Penton was sold, all of the download links in my articles are broken, unfortunately. I have posted the script on GitHub:
https://gist.github.com/Bill-Stewart/d52bebe553fbfe01deebe745ce650bc0
BaltoStar
Updated on August 08, 2020Comments
-
BaltoStar over 3 years
Logged-in to
$ComputerName
as local Administrator Windows Server 2008 R2 SP1This script :
$admin=[adsi]("WinNT://" + $ComputerName + "/administrator, user") $admin.psbase.invoke("SetPassword", $Password) $admin.psbase.CommitChanges()
run locally throws exception :
Exception calling "Invoke" with "2" argument(s):"The network path was not found"