FOR/DO command gives "Was unexpected at this time" when run from command prompt

When referencing For loop variable within a batch file you need to double up the percent signs (ie: %%a), but if you do this when just running the command straight at the prompt it won't work. You need to change them to a single percent sign (%a).

Perhaps check out this other SU question for more info: What does the percent sign (% and %%) in a batch file argument mean?