batch script to full use's last name based on sam id

Posted on 2011-05-12
Last Modified: 2012-05-11
Hi All,

I have this script to read in text file that contains list of user's logon name, then I want it to give me user's firstname and lastname based on it. But it keeps telling me"%%L" is unexpected at this time.

Could someone look at this and tell me what is wrong? Thanks

Cfor /f %%L in (c:\test.txt) do dsquery user -samid %%L | dsget user -ln
Question by:fireburn11
    LVL 43

    Accepted Solution

    Are you running it from cmd.exe directly instead of a bcth file by any chance?  You use double %% signs with FOR commands in a batch file and single % from cmd.exe directly, i.e.

    for /f %L in (c:\test.txt) do dsquery user -samid %L | dsget user -ln

    Author Comment

    That did the trick, i didn't know you can only use one "%" when you run in cmd.exe.

    Thanks for the help!
    LVL 43

    Expert Comment

    by:Steve Knight
    No problem, yup just one of those gotchas!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    760 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

    13 Experts available now in Live!

    Get 1:1 Help Now