Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell : change local Administrator password

Tags:

powershell

Logged-in to $ComputerName as local Administrator Windows Server 2008 R2 SP1

This 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"

like image 289
BaltoStar Avatar asked May 13 '13 22:05

BaltoStar


People also ask

How do I change my local administrator password using CMD?

In the Command Prompt window, type the password reset command: net user <username> <password> and hit Enter to set a new password for your Windows 10 local admin account. Once password reset is complete, close the Command Prompt and then you can sign into the admin account with the new password.

How do I add a local admin to PowerShell?

To add the AD user or the local user to the local Administrators group using PowerShell, we need to use the Add-LocalGroupMember command. You can also add the Active Directory domain user to the Local Administrators group by providing the domain name if the computer is in the same domain.


2 Answers

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)
like image 126
Jan Avatar answered Oct 23 '22 12:10

Jan


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

like image 40
Tyson Smith Avatar answered Oct 23 '22 11:10

Tyson Smith