1

I want to write a batch file that saves specific user account information's by using the windows command "net user account /domain". Problem is when I use the findstr the output is not written into the file:

set userlist = user1 user2 user3
for %x in (userlist) do (
net user %x /domain | findstr /B /C:"Last logon"  > D:\userInfoList.txt
)

This is just an example. At the end I want for every user an entry like this but with the actual informations. username; lastLogin; nextPasswortChange etc. How can I build such an output?

Thanks in advance!

Nero
  • 37
  • 1
  • 5
  • 3
    1. Do not put spaces around the `=` in the `set` command line as they become part of the variable mane and value otherwise. 2. read variables like `%userlist%`. 3. Use `%%x` in the `for` loop as `%x` works only in case you are executing it in command prompt (`cmd`) directly. – aschipfl Jul 05 '16 at 15:13
  • 2
    One more thing to change: Your code will only save the last value because it will overwrite each time through the loop. Typically I do something like this prior to the FOR loop. set "OutFile=D:\userInfoList.txt" if exist "%OutFile%" del /q "%OutFile%" Then use >>"%OutFile%" instead of > D:\userInfoList.txt. This also has the advantage that it gets rid of the output from the previous run if you run it twice. – RGuggisberg Jul 05 '16 at 15:21

0 Answers0