• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 401
  • Last Modified:

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

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
  • 2
1 Solution
Steve KnightIT ConsultancyCommented:
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
fireburn11Author Commented:
That did the trick, i didn't know you can only use one "%" when you run in cmd.exe.

Thanks for the help!
Steve KnightIT ConsultancyCommented:
No problem, yup just one of those gotchas!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now