Ensure the target computer is reachable. The script below confirms if RemotePC is online.
Test-Connection -ComputerName "RemotePC" -Count 2Set a new password for a local user. This changes the password for LocalUser on the local machine.
$Password = ConvertTo-SecureString "NewPassword123!" -AsPlainText -Force Set-LocalUser -Name "LocalUser" -Password $PasswordUse PowerShell remoting to change the password remotely. This updates LocalUser’s password on RemotePC.
Invoke-Command -ComputerName "RemotePC" -ScriptBlock {
$Password = ConvertTo-SecureString "NewPassword123!" -AsPlainText -Force
Set-LocalUser -Name "LocalUser" -Password $Password
}Update passwords on multiple computers. The script below updates LocalUser's password on all specified computers.
$computers = @("PC1", "PC2", "PC3")
foreach ($computer in $computers) {
Invoke-Command -ComputerName $computer -ScriptBlock {
$Password = ConvertTo-SecureString "NewPassword123!" -AsPlainText -Force
Set-LocalUser -Name "LocalUser" -Password $Password
}
}Run the script below to reset a local user password remotely. Replace RemotePC with the actual remote system.
Invoke-Command -ComputerName RemotePC -ScriptBlock { net user Administrator "NewPass@123" }Yes, you can change passwords on multiple remote machines by running the script below.
$computers = @("PC1", "PC2", "PC3")
Invoke-Command -ComputerName $computers -ScriptBlock { net user Administrator "NewPass@123" }Yes, you must run PowerShell as an administrator.