1

Im writing a windows batch script and I need to set all the users to a certain password? I know that I can do net user to see all users on the computer and I can do net user username password to set the password of a user. But Is there a way to combine these two commands to set all the users to a specific passwords.

3
  • No; Could write a powershell script that performed a loop and at each user, set the password, but there is no command because setting severe username to the same password is a horrible security practice it means anyone can log into any account with that password
    – Ramhound
    Feb 19, 2016 at 2:28
  • Could also make a quick list of usernames to a text file each line will be a different user name and then a quick batch FOR /F "TOKENS=*" %F IN (FileList.txt) DO net user %~F password Feb 19, 2016 at 2:31
  • Can I do "net user >> user.txt" and then run the above command?
    – john1527
    Feb 19, 2016 at 3:01

1 Answer 1

0

Setting several username to the same password is a horrible security practice. It means anyone can log into any account with that password – Ramhound

However, next batch code snippet shows a way how-to get active user list. As soon as you remove ECHO from 6th line, you can see if it works with net command (could require administrator privileges and run elevated):

@ECHO OFF
SETLOCAL EnableExtensions
FOR /F "TOKENS=2* delims==" %%G IN ('
        wmic USERACCOUNT where "status='OK'" get name/value  2^>NUL
    ') DO for %%g in (%%~G) do (
            ECHO net user %%~g
          )

Here the for loops are

  • %%G to retrieve the active user name value;
  • %%g to remove the ending carriage return in the value returned: wmic behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).

See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem

Resources (required reading):

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .