Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • 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
0
fireburn11
Asked:
fireburn11
  • 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
0
 
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!
0
 
Steve KnightIT ConsultancyCommented:
No problem, yup just one of those gotchas!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

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