- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to change the local user account password using PowerShell?
To change the local user account password using PowerShell, we can use the Set-LocalUser command with the Password parameter. This password parameter should be in the secure string. So we need to ask the user to input the password as a secure string or need to explicitly convert the plain text password to the secure string. For example,
$localuser = Read-Host "Enter Local UserName" $password = Read-Host "Enter local user account password " -AsSecureString Set-LocalUser -Name $localuser -Password $password -Verbose
If you need to set the password without asking the user prompt then you need to convert the plain text password to the secure string forcefully as shown below.
$password = "Admin123" | ConvertTo-SecureString -AsPlainText -Force Set-LocalUser -Name TestUser -Password $password -Verbose
To set the local user password on the remote computer, use Invoke-Command.
Invoke-Command -ComputerName Computer1, Computer2 -ScriptBlock{ $password = "Admin123" | ConvertTo-SecureString -AsPlainText -Force Set-LocalUser -Name 'TestUser' -Password $password -Verbose }
The above command will set the local user account password on the remote servers computer1 and Computer2.
Advertisements