Posted on 2012-09-02
Last Modified: 2012-09-07
I want to how to loop with FOR commands:

Say for example I have list of users in a file called users.txt. I need to find the properties of each users in the users.txt.

net user <username> will give the properties of a username. How to loop so that I can get the properties of each users in Users.txt file

Question by:jmohan0302
    LVL 95

    Accepted Solution

    Have you typed "for /?" or reviewed any of the questions here?

    It's very simple:

    FOR /f %a in (users.txt) do @net user %a
    LVL 14

    Assisted Solution

    for /F %A in (myfile.txt) do net user %A

    if you are going to use it as part of a script then you need to use double %

    for /F %%A in (myfile.txt) do net user %%A
    LVL 39

    Assisted Solution

    by:Krzysztof Pytko
    Just only to add, out of discussion

    Follow leew'a syntax which does all you need but at the end add redirection to file. It would be much more easy to identify those properties for users

    FOR /f %a in (users.txt) do @net user %a >%a.txt

    Open in new window

    when you run that all user properties will be redirected to a text file named from user name.

    LVL 1

    Expert Comment

    for user in `cat users.txt`
              net user $user

    Author Comment

    LVL 95

    Expert Comment

    by:Lee W, MVP
    Could you explain why I was not awarded a portion of the points considering I posted first with the exact same answer (in part) as the TheRuck and iSiek's answer built on (even referenced) mine?
    LVL 14

    Expert Comment

    i guess for your attitude in your post :)
    LVL 95

    Expert Comment

    by:Lee W, MVP
    So I shouldn't explain how someone might find an answer better or more importantly faster by simply typing for /? ?

    I believe in TEACHING not just giving an answer.  Sorry you disagree.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
    Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now