I am using CSVDE to export some user info out of AD. I need to loop over several domain controllers and export data from each one to a separate csv file. To do so, I am using the following batch script (only 1 domain controller / file is displayed for simplicity):
ECHO %time%
@ECHO OFF
SET userName=SomeLogin
SET pass=SomePassword
SET domain=SomeDomain
SET columnName=-l givenname,lastLogon,userAccountControl,lastLogonTimestamp,sn,userPrincipalName,displayname,mail,samaccountname,pwdLastSet,whenCreated,whenChanged SET filter="(&(objectClass=User)(objectCategory=Person))"
SET len=1
SET data[0].file=some_file.csv
SET data[0].DC=someIP
SET i=0
:LOOP
IF %i% equ %len% GOTO :EOF
SET cur.file=
SET cur.DC=
FOR /f "usebackq delims==. tokens=1" %%j IN (`SET data[%i%]`) DO (
SET cur.%%k=%%l
)
csvde -f %cur.file% -r %filter% %columnName% -s %cur.DC% -b %userName% %domain% %pass% -u
SET /a i = %i% + 1
@ECHO ON
ECHO %time%
When I run this script, I get the following error:
Invalid Parameter: Bad argument '(&(objectClass=User)(objectCategory=Person))'
When I run CSVDE outside of this script (i.e., outside of a loop), it runs just fine. So, it must have something to do with the fact that it's in a loop. But, I can't figure out why and how to resolve it. What do I need to change to resolve this issue?