PowerShell: change the local administrator password

Logging on to $ComputerName as a Local Administrator for Windows Server 2008 R2 SP1

This script:

 $admin=[adsi]("WinNT://" + $ComputerName + "/administrator, user") $admin.psbase.invoke("SetPassword", $Password) $admin.psbase.CommitChanges() 

throw a local exception: Exception calling "Invoke" with "2" argument(s):"The network path was not found"

+4
source share
4 answers

When I wanted to change the local administrator password on all servers in the AD domain, I just used the remote PS move, which allows me to push even very simple commands from CMD to the remote server.

I wrote a short script where I use powershell to get information from a domain controller and, based on certain conditions, press the command on the servers.

I find this a very simple and quick way to change the local administrator password. The only requirement is to enable WinRM on all servers.

Below is the script:

 Invoke-Command -ScriptBlock {net user administrator "Password01"} -ComputerName (Get-ADComputer -SearchBase "OU=test,OU=servers,DC=lab,DC=com" -Filter * | Select-Object -Expand Name) 
+3
source

Did not check it, but found

 ([adsi]"WinNT://<Local or Remote Computer Name>/<Username>").SetPassword("<Password>") 

http://www.petri.co.il/how-to-change-user-password-with-powershell.htm

+1
source

If your goal is to really change the password of the administrator account (regardless of whether it has been renamed - it is not always called "Administrator"), I recommend using a script, as in this article:

Windows IT Pro: resetting the local administrator password on computers

The Reset -LocalAdminPassword.ps1 script specified in the article uses ADSI to download to connect to remote systems, so it is assumed that remote administration is allowed through the firewall of the remote computer.

+1
source

For a local computer, this works

 $comp=hostname ("WinNT://" + $comp + "/<user_name_to_change_password_for>").SetPassword("<actualpasswordtext>") 
0
source

Source: https://habr.com/ru/post/1480596/


All Articles