- 17 May 2024
- 2 Minutes to read
- Print
- PDF
Update Local User passwords on multiple devices
- Updated on 17 May 2024
- 2 Minutes to read
- Print
- PDF
This PowerShell script helps IT Admins to change the passwords of the Local User accounts (Standard accounts) on Windows 10 and above devices. It will help IT Admins to push a new password to one or more local use on one or more devices.
- Create a file on your desktop, for example, update_different_local_user_passwords_on_devices.ps1 and open it in a text editor like notepad++
- Copy the contents below to the file or click hereto download the file.Shell
# update below json as per target devices $computerlist = @' [ { "computername": "computer_name", "userlist": [ {"username": "user_name","password": "new_password"}, ] }, ] '@ ($computerlist | ConvertFrom-Json) | ForEach-Object { $computer = $_.computername $localcomputer = [System.Net.Dns]::GetHostName() if($computer -eq $localcomputer) { $_.userlist | ForEach-Object { $User = $_.username $Password = $_.password $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force $UserAccount = Get-LocalUser -Name $User $UserAccount | Set-LocalUser -Password $SecurePassword } } }
- Replace the content in front of the placeholder "computer_name": in the script with the actual computer name. For example:
{ "computername": "DESKTOP1",
- Replace the content of the placeholder "user_name": with the actual Local user account name and replace the content of the placeholder "new_password": with the new password that you would like to set for that local user. For example:
"userlist": [ {"username": "John Smith","password": "pswd1"}, ]
- Once done, save the file and proceed to upload the script on the dashboard.
- Please make sure to select the Execution Policy as below
a. Execution Level : Device
b. Execution Context : Enrolled User - Follow our guide to upload & publish the PowerShell script using Scalefusion Dashboard.
- Once the script is successfully executed, you will be able to see the status of the same in the View Statusreport on the Scalefusion dashboard.
- Click on the PowerShell script and click on the View Status report.
- Executed means that the script has run successfully on the device.
You can also change the password for more than one local user on more than one device. As before, the process remains the same, that is, replace the content in front of the placeholder "computername": in the script with the actual name of the computers (for multiple computers).
Replace the content in front of the placeholder "user_name": with the actual Local user account names (for multiple users) and replace the content in front of the placeholder "new_password": with the new password that you would like to set for those local users.
An example for changing passwords for multiple users on different machines is shown below. Please change the components accordingly.
$computerlist = @'
[
{
"computername": "computer1",
"userlist":
[
{"username": "user1","password": "pswd1"},
{"username": "user2","password": "pswd2"},
]
},
{
"computername": "computer2",
"userlist":
[
{"username": "user4","password": "pswd4"},
{"username": "user5","password": "pswd5"}
]
},
]
'@
($computerlist | ConvertFrom-Json) | ForEach-Object {
$computer = $_.computername
$localcomputer = [System.Net.Dns]::GetHostName()
if($computer -eq $localcomputer) {
$_.userlist | ForEach-Object {
$User = $_.username
$Password = $_.password
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$UserAccount = Get-LocalUser -Name $User
$UserAccount | Set-LocalUser -Password $SecurePassword
}
}
}
- The scripts and their contents are sourced from various albeit authenticated Microsoft sources and forums.
- Please validate the scripts on a test machine before deploying them on all your managed devices.
- Scalefusion has tested these scripts, however, Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the incorrect usage of these scripts.