0

I have the following .bat script:

FOR /f "skip=1" %%x IN ('wmic os get localdatetime') DO IF NOT DEFINED MyDate SET MyDate=%%x
SET today=%MyDate:~0,4%%MyDate:~4,2%%MyDate:~6,2%

SET fileext=".csv"

SET Username=some_user
SET Password=some_password
SET Domain=some_domain

SET LDAPport=3268

SET LDAPAttributeList=sAMAccountName
SET LDAPfilter="(&(objectClass=User)(objectCategory=Person))"

FOR /F "tokens=1,2 delims=|" %%G IN (files_DCs_map.txt) DO (
    csvde -f %%G%today%fileext -r %LDAPfilter% -l %LDAPAttributeList% -t %LDAPport% -s %%H -b %Username% %Domain% %Password% -u
)

This script uses the csvde utility to extract data out of a Windows AD domain controller and write it to a file. The file name and domain controller IP is stored in file files_DCs_map.txt. A sample line in this file is:

some_DC|some_IP

The script works, but it is outputting incorrect file names. I want file names in the form <some_DC><today>.csv. It is currently outputting file names in the form <some_DC><today>fileext. That is, it's not interpreting variable fileext correctly. For example, it outputs file name some_DC20171128fileext. I want this file name to be some_DC20171128.csv instead. How can I achieve this?

1 Answer 1

1

Regular variables in batch need to be enclosed in percent signs. You have specified the filename as

%%G%today%fileext

%%G is the loop variable. %today% is the date, which works as you expect. filext, missing the percents, is just a literal. You need to put it like this:

%%G%today%%fileext%
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.