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?