Users: Reset all users passwords using batch or powershell?

0

1

I need to bulk reset passwords on a local machine (No network or domain just the machine) to a single password; such as %1Percent . I was wondering if this was at all possible with batch or power shell or some sort of script.

TheiMacNoob

Posted 2017-01-16T04:20:07.280

Reputation: 21

Answers

5

With Powershell (Adminstrator privileges required):

  • get new password from user input as a SecureString
  • Get-Localuser enumerates all local users and pipes them to the
  • where clause which checks against the users to exclude
  • Remaining users are piped to Set-Localuser which sets the password entered in the first command.

#Requires -RunAsAdministrator
$SecurePassword = Read-Host -Prompt "Enter password for all users" -AsSecureString 
$Exclude = "Administrator","Guest","DefaultAccount"
Get-LocalUser |
  Where {$Exclude -notcontains $_.Name} |
    Set-Localuser -Password $SecurePassword

LotPings

Posted 2017-01-16T04:20:07.280

Reputation: 6 150

Maybe it would be good if you could add explanations for your script ? – Ob1lan – 2017-01-17T09:49:11.740

0

Create text file with extension cmd such as nuke_users_passwords.cmd

with following content (substitute username and password as you need) and run it

@echo off
net user username1  new_password
net user username2  new_password
...
net user usernameN  new_password

Another solution is to use WMI to automatically enumerate local users and change their passwords.

Below is the VBS script with ability to exclude some of account(s) that need to be skipped. Save it as FileName.vbs and run it "as administrator"

On Error Resume Next 

strPasswd = "SuperPassword"
strComputer = "." 

Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Set colItems = objWMIService.ExecQuery _ 
    ("Select * from Win32_UserAccount Where LocalAccount = True") 

For Each objItem in colItems 
    Do While True
        if objItem.Name = "Guest" then Exit Do ' Skip some account
        if objItem.Name = "Administrator" then Exit Do ' Skip some account
        if objItem.PasswordChangeable = False then Exit Do ' 

        objItem.SetPassword strPasswd
        objItem.SetInfo 

        Exit Do
    Loop
Next 

Wscript.Echo "Done."

P.S. Run these scripts "as administrator"

Alex

Posted 2017-01-16T04:20:07.280

Reputation: 5 606

I know this way but I am dealing with possibly hundreds of accounts. It would be better if I didnt have to do one at a time. – TheiMacNoob – 2017-01-16T15:52:37.083

Oh, it make sense. I updated my answer, check it – Alex – 2017-01-16T21:15:24.350