was unexpected at this time – windows batch scripts

Haven’t had to write batch scripts for a while, forgot the FOR syntax. Most annoying was remembering that the variable name can’t be more than a character, such as:

for /L %foo in (1,1,254) do echo %foo
%foo was unexpected at this time.

If you just change foo to x it works fine, i.e. for updating dns entries quickly:

for /L %x in (1,1,254) do dnscmd domaincontroller /recordadd yourdomain.com 192.168.10-%x.vpn A 192.168.10.%x
for /L %x in (1,1,254) do dnscmd domaincontroller /recordadd 10.168.192.in-addr.arpa. %x PTR 192-168-10-%x.vpn.yourdomain.com.

Note that the later creates leafs with records using @ (parent folder). This is visually annoying. I don’t know another way to do it. Seems to work find and for whatever reason other entries start to follow this tree like automatically registered DNS from clients. Not that YOU are using dns to track if an IP address is available or not anyways.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.