Automating Local Administrator Password Changes on Windows Machines with PowerShell

Table of Contents

Introduction

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.

Script Overview

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.


					
				

Network Scanning

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.


					
				

Full Script


					
				
Total
0
Shares
Previous Post

User PowerShell To Bulk Change users Password

Next Post

Delete Old User Profiles in Windows

Related Posts

How to Set Proxy Settings via Group Policy?

The article shows how to use Active Directory Group Policies (GPOs) to configure proxy server settings on domain-joined computers running Windows 10/11 and Windows Server 2022/2019/2016/2012R2. These proxy server settings are used by all modern browsers, including Internet Explorer 11 (reached end of support on June 2022), Google Chrome, Microsoft Edge, Opera, and Mozilla Firefox
Read More

How to Convert ESD to WIM File on Windows

In this tutorial, we will show you how to convert ESD to WIM file from the Command prompt, using the DISM tool, or PowerShell scripts. ESD file is a new highly compressed image distribution format developed by Microsoft. The ESD (Electronic Software Download) image files are used to deploy the Windows operating system instead of
Read More