Automating Local Administrator Password Changes on Windows Machines with PowerShell
Table of Contents
PowerShell is a powerful scripting language that can be used to automate various tasks, including managing Windows machines. One common task is changing the local administrator account password on multiple machines. This can be a tedious and time-consuming task if done manually, but PowerShell can make it much easier and faster.
The PowerShell script I provided can be used to change the local administrator account password on a list of remote machines or by scanning the network for active machines. Let’s take a closer look at how the script works.
Setting the New Password and Computer List
First, we specify the new password for the local administrator account and the path to the file containing the list of remote machines (if using the hostname list method). These values can be updated as needed to fit your specific requirements.
Looping Through the List of Remote Machines
Next, we read the list of remote machines from the text file (if using the hostname list method) and loop through each machine in the list.
Changing the Local Administrator Account Password
For each machine, we use PowerShell remoting to connect to the remote computer and change the local administrator account password using the
Set-LocalUser cmdlet. This cmdlet allows us to specify the username (in this case, “Administrator”) and the new password as a secure string.
If using the network scanning method, the script uses the
Test-Connection cmdlet to ping each IP address in the specified range and check for active machines. Then, it loops through each active machine and changes the local administrator account password using the same method as before.