Using PowerShell to change passwords is especially great for administrators, IT professionals, and power users who need automation, customization, and the ability to manage multiple accounts easily. This can save a lot of time and make things much more organized and controlled.
Remember, PowerShell can only be used to change passwords for local accounts on the computer itself, not for Microsoft accounts that you use to sign into the PC. For Microsoft accounts, you'll need to change the password either through the Microsoft website or your account settings.
In this article, we will explore several different commands to change the password of your Windows 11 local account using PowerShell.
Change Account Password on Windows 11 using PowerShell
In PowerShell, there are several different commands that can be used to change passwords for local user accounts. Here is the syntax and a few examples:
First, search for PowerShell
in the Start menu, click on 'Run as administrator' on the right pane to open it. Then, click 'Yes' to the User Account Control prompt.
Using Net User Command
The net user command is a command-line utility that has existed in Windows for a long time. It's used to manage user accounts, including password changes, directly from Command Prompt or PowerShell.
In the PowerShell window, type the following command to change the password and hit Enter
:
net user Username NewPassward
Replace Username
with the actual username of the account you want to change the password for, and NewPassword
with the new password you want to set.
Example:
For example, if the username is 'Kalki51' and you want to set the new password to 'Saht!3225', the command will be:
net user kalki51 Saht!3225
Though this command can change the password of the user account, it isn't generally advisable to enter passwords in plaintext in the command line. Since the command can be stored in the command history, anyone with access to the machine can view it. You should either clear the history or use a secure method as outlined below.
Using Set-LocalUser Command
You can also use the Set-LocalUser cmdlet to change the password for the user account:
Set-LocalUser -Name "Username" -Password (ConvertTo-SecureString -AsPlainText "NewPassword" -Force)
Replace Username
with the actual username of your account and NewPassword
with the new password you want to set.
The ConvertTo-SecureString
cmdlet is used to turn the plain text password into a secure string format. The -AsPlainText
parameter specifies that you're providing the password in plain text, and the -Force
parameter is used to suppress any confirmation prompts.
Example:
Set-LocalUser -Name "kalki51" -Password (ConvertTo-SecureString -AsPlainText "tax234@52" -Force)
After running the command, it won't provide any confirmation message. To verify that the password has been changed, you can try logging in with the new password.
Using the WMI Win32_UserAccount Class command
Another command you can use to set a new password for the user account is Windows Management Instrumentation (WMI) tool. Type the following command and press Enter
on each line:
$user = Get-WmiObject Win32_UserAccount -Filter "Name='<Username>'"
$user.SetPassword("<NewPassword>")
Example:
$user = Get-WmiObject Win32_UserAccount -Filter "Name='<kalki52>'"
$user.SetPassword("<pswd12345>")
Using Get-LocalUser and Set-LocalUser cmdlets
Enter the below command to list all the available accounts on your computer, and press Enter
:
Get-LocalUser
Input the following command to generate and store the new password in a variable, and press Enter
:
$Password = Read-Host "Enter new password" -AsSecureString
Type the new password for the account and hit Enter
.
Enter the below commands and hit Enter
after typing each line. This will set the new password for the local account.
$UserAccount = Get-LocalUser -Name "kalki51"
$UserAccount | Set-LocalUser -Password $Password
Replace Username
with the account name.
That's it. These were some different ways you can use Powershell to change the account password in Windows 11, for whatever reason you need to change it.
Member discussion